コード例 #1
0
  @Override
  public void run(final Network network) {
    super.run(network);

    log.info("Putting landmarks on network...");
    long now = System.currentTimeMillis();
    landmarks = landmarker.identifyLandmarks(landmarkCount, network);
    log.info("done in " + (System.currentTimeMillis() - now) + " ms");

    log.info("Initializing landmarks data");
    for (Node node : network.getNodes().values()) {
      this.nodeData.put(node, new LandmarksData(this.landmarkCount));
    }

    int nOfThreads = this.numberOfThreads;
    if (nOfThreads > this.landmarks.length) {
      nOfThreads = this.landmarks.length;
    }
    if (nOfThreads < 2) {
      nOfThreads = 2; // always use at least two threads
    }
    log.info(
        "Calculating distance from each node to each of the "
            + this.landmarkCount
            + " landmarks using "
            + nOfThreads
            + " threads...");
    now = System.currentTimeMillis();

    ExecutorService executor = Executors.newFixedThreadPool(nOfThreads);
    for (int i = 0; i < this.landmarks.length; i++) {
      executor.execute(new Calculator(i, this.landmarks[i], this.nodeData, this.costFunction));
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
      log.info("wait for landmarks Calculator to finish...");
      try {
        executor.awaitTermination(10, TimeUnit.MINUTES);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }

    for (Node node : network.getNodes().values()) {
      LandmarksData r = getNodeData(node);
      r.updateMinMaxTravelTimes();
    }

    for (Node node : network.getNodes().values()) {
      LandmarksData r = getNodeData(node);
      for (int i = 0; i < this.landmarks.length; i++) {
        if (r.getMinLandmarkTravelTime(i) > r.getMaxLandmarkTravelTime(i)) {
          log.info("Min > max for node " + node.getId() + " and landmark " + i);
        }
      }
    }

    log.info("done in " + (System.currentTimeMillis() - now) + " ms");
  }
コード例 #2
0
 private void expandLandmarkTo() {
   LandmarksToTravelTimeComparator comparator =
       new LandmarksToTravelTimeComparator(this.nodeData, this.landmarkIdx);
   PriorityQueue<Node> pendingNodes = new PriorityQueue<>(100, comparator);
   LandmarksData role = (LandmarksData) this.nodeData.get(this.landmark);
   role.setToLandmarkTravelTime(this.landmarkIdx, 0.0);
   role.setFromLandmarkTravelTime(this.landmarkIdx, 0.0);
   pendingNodes.add(this.landmark);
   while (!pendingNodes.isEmpty()) {
     Node node = pendingNodes.poll();
     double toTravTime =
         ((LandmarksData) this.nodeData.get(node)).getToLandmarkTravelTime(this.landmarkIdx);
     LandmarksData role2;
     for (Link l : node.getInLinks().values()) {
       Node n = l.getFromNode();
       double linkTravTime = this.costFunction.getLinkMinimumTravelDisutility(l);
       role2 = (LandmarksData) this.nodeData.get(n);
       double totalTravelTime = toTravTime + linkTravTime;
       if (role2.getToLandmarkTravelTime(this.landmarkIdx) > totalTravelTime) {
         role2.setToLandmarkTravelTime(this.landmarkIdx, totalTravelTime);
         pendingNodes.add(n);
       }
     }
   }
 }