Beispiel #1
0
    @Override
    public void run() {
      Collection<Node> nodes = zone2Node.get(originId);

      for (Node node : nodes) {
        sTree.setOrigin(node);
        sTree.setDepartureTime(0);
        sTree.run(network);

        for (Entry<Node, NodeData> entry : sTree.getTree().entrySet()) {
          String targetId = node2Zone.get(entry.getKey().getId());
          if (targetId != null) {
            CellData cData = ttMatrix.get(originId, targetId);

            if (cData == null) {
              cData = new CellData();
              ttMatrix.set(originId, targetId, cData);
            }

            cData.count++;
            cData.ttSum += entry.getValue().getCost();
          } else {
            errors++;
          }
        }
        logger.info("Processed node...");
      }
    }
Beispiel #2
0
  public NumericMatrix generate(
      Network network, ZoneCollection zones, String zoneIdKey, int nThreads) {
    this.network = network;

    logger.info("Initializing node mappings...");
    initMappings(zones, zoneIdKey);

    logger.info("Calculation travel times...");
    ExecutorService executor = Executors.newFixedThreadPool(nThreads);
    Set<Future<Worker>> futures = new HashSet<>();

    for (Zone zone : zones.getZones()) {
      Worker worker = new Worker(zone.getAttribute(zoneIdKey));
      futures.add(executor.submit(worker, worker));
    }

    ProgressLogger.init(futures.size(), 1, 10);

    HashMatrix<String, CellData> sumMatrix = new HashMatrix<>();
    int errors = 0;

    for (Future<Worker> future : futures) {
      try {
        Worker worker = future.get();
        HashMatrix<String, CellData> m = worker.getMatrix();
        Set<String> keys = m.keys();

        for (String i : keys) {
          for (String j : keys) {

            CellData cData = m.get(i, j);
            if (cData != null) {

              CellData cDataSum = sumMatrix.get(i, j);
              if (cDataSum == null) {
                cDataSum = new CellData();
                sumMatrix.set(i, j, cDataSum);
              }

              cDataSum.count += cData.count;
              cDataSum.ttSum += cData.ttSum;
            }
          }
        }

        errors += worker.getErrors();

        ProgressLogger.step();
      } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace();
      }
    }

    ProgressLogger.terminate();

    if (errors > 0) {
      logger.info(String.format("%s errors occured.", errors));
    }

    logger.info("Collection results...");

    NumericMatrix ttMatrix = new NumericMatrix();
    Set<String> keys = sumMatrix.keys();
    for (String i : keys) {
      for (String j : keys) {
        CellData cData = sumMatrix.get(i, j);
        double avr = cData.ttSum / cData.count;
        ttMatrix.set(i, j, avr);
      }
    }

    return ttMatrix;
  }