Example #1
0
  {
    nwr.readFile(
        "/Users/fouriep/IdeaProjects/matsim/matsim/examples/siouxfalls-2014/Siouxfalls_network_PT.xml");
    network = scenario.getNetwork();
    //		nca = new IntraMinDeltaOutLinksNCA(scenario.getNetwork());
    //		nca = new IntraMaxNCA(scenario.getNetwork(),"getCapacityTimesSpeed",null,null);
    nca =
        new MinmizeNumberOfOutlinksNCA(scenario.getNetwork(), "getCapacityTimesSpeed", null, null);
    nca.run();

    //		new ClusterReader().readClusters("~/Desktop/test.txt", scenario.getNetwork(), nca);
    colorsForDisplay = new int[nca.getPointersToClusterLevels().size()];
    getRandomColors((int) nca.getClusterSteps());
  }
Example #2
0
  @Override
  public void draw() {
    // stroke(0);

    if (change) {
      println(currentStep + ":" + colorsForDisplay.length);
      background(255);
      pushMatrix();
      if (followMouse) {
        translate(mouseX - width / 2, mouseY - height / 2);
      }
      if (width / height < (maxX - minX) / (maxY - minY))
        scale(width / (maxX - minX), -width / (maxX - minX));
      else scale(height / (maxY - minY), -height / (maxY - minY));
      ArrayList<NodeCluster> clustersAtLevel = nca.getClustersAtLevel(currentStep);
      NodeCluster largestCluster = nca.getLargestCluster(clustersAtLevel);
      println("largest: " + largestCluster.getId());
      translate(-minX, -maxY);

      for (NodeCluster nc : clustersAtLevel) {
        if (nc.isLeaf()) {
          for (ClusterLink link : nc.getOutLinks().values()) {
            strokeWeight(strokeWeights.get(link.getId()));

            stroke(color(240));
            // pushMatrix();
            line(
                (float) (link.getFromNode().getCoord().getX()),
                (float) (link.getFromNode().getCoord().getY()),
                (float) (link.getToNode().getCoord().getX()),
                (float) (link.getToNode().getCoord().getY()));
          }

        } else {

          for (ClusterLink link : nc.getInterLinks().values()) {
            strokeWeight(strokeWeights.get(link.getId()));
            int colindex = nc.getId();
            if (nc.equals(largestCluster)) {
              stroke(color(255, 0, 0));
            } else {
              stroke(colorsForDisplay[colindex]);
            }
            // pushMatrix();
            line(
                (float) (link.getFromNode().getCoord().getX()),
                (float) (link.getFromNode().getCoord().getY()),
                (float) (link.getToNode().getCoord().getX()),
                (float) (link.getToNode().getCoord().getY()));
          }
          for (ClusterLink link : nc.getOutLinks().values()) {
            strokeWeight(strokeWeights.get(link.getId()));
            stroke(color(200));
            // pushMatrix();
            line(
                (float) (link.getFromNode().getCoord().getX()),
                (float) (link.getFromNode().getCoord().getY()),
                (float) (link.getToNode().getCoord().getX()),
                (float) (link.getToNode().getCoord().getY()));
          }
        }
      }
      // println(currentStep+":"+clustersAtLevel);

      // for (Link link : network.getLinks().values()) {
      // // popMatrix();
      // }
      // for (Node n:network.getNodes().values()){
      //
      // }
      popMatrix();
      change = false;
      // currentStep++;
      fill(0);
      text(currentStep + ":" + (colorsForDisplay.length - 1), 20, 20);
    }
    if (this.mousePressed) {
      change = true;
      followMouse = true;
    }

    //		 do some frame counting
    //		 fcount += 1;
    //		 int m = millis();
    //		 if (m - lastm > 1000 * fint) {
    //		 frate = (float) fcount / fint;
    //		 fcount = 0;
    //		 lastm = m;
    //		 // println("fps: " + frate);
    //		 }
    //		 text(frate, 0, 20);
  }