@Override
 public void process(
     ActivityFacility quelle,
     ActivityFacility ziel,
     int quantity,
     String mode,
     String destinationActivityType,
     double departureTimeOffset) {
   Node quellNode = NetworkUtils.getNearestNode(((Network) network), quelle.getCoord());
   Node zielNode = NetworkUtils.getNearestNode(((Network) network), ziel.getCoord());
   Path path = dijkstra.calcLeastCostPath(quellNode, zielNode, 0.0, null, null);
   double travelTimeToWork = calculateFreespeedTravelTimeToNode(this.network, path, zielNode);
   //		if(quelle.id == 9375 && ziel.id == 9162){
   System.out.println(
       "from zone "
           + quelle.getId()
           + " to zone "
           + ziel.getId()
           + ", it takes "
           + travelTimeToWork
           + " seconds to travel.");
   sink.process(
       quelle,
       ziel,
       quantity,
       mode,
       destinationActivityType,
       departureTimeOffset - travelTimeToWork);
   //		}
 }
Esempio n. 2
0
  public static void main(String[] args) {
    Scenario scenario;
    scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
    new NetworkReaderMatsimV2(scenario.getNetwork()).readFile(args[0]);
    Network network = scenario.getNetwork();
    Network net = NetworkUtils.createNetwork();
    Set<String> modes = new HashSet<>();
    modes.add(TransportMode.car);
    new TransportModeNetworkFilter(network).filter(net, modes);
    new NetworkCleaner().run(net);
    MatsimRandom.reset(123);
    DrunkDudePathfinder stochasticRouter =
        new DrunkDudePathfinder(
            net,
            new TravelDisutility() {

              @Override
              public double getLinkTravelDisutility(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }

              @Override
              public double getLinkMinimumTravelDisutility(Link link) {
                return link.getLength() / link.getFreespeed();
              }
            },
            new TravelTime() {

              @Override
              public double getLinkTravelTime(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }
            },
            0.5);
    SimpleNetworkPainter networkPainter = new SimpleNetworkPainter(400, 400);
    networkPainter.setNetworkTransformation(network);
    stochasticRouter.setNetworkPainter(networkPainter);
    //        stochasticRouter.calcLeastCostPath(network.getNodes().get(Id.createNodeId("11_311")),
    //                network.getNodes().get(Id.createNodeId("18_566")), 3600, null, null);
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.addAll(net.getNodes().values());
    Node[] nodesArray = nodeSet.toArray(new Node[nodeSet.size()]);

    long currentTimeMillis = -System.currentTimeMillis();
    for (int i = 0; i < 1e3; i++) {
      int[] ints = Sample.sampleMfromN(2, nodesArray.length);
      System.out.println(nodesArray[ints[0]] + " " + nodesArray[ints[1]]);
      stochasticRouter.calcLeastCostPath(
          nodesArray[ints[0]], nodesArray[ints[1]], 3600, null, null);
    }
    currentTimeMillis += System.currentTimeMillis();
    System.out.println(currentTimeMillis);

    Dijkstra dijkstra =
        new Dijkstra(
            net,
            new TravelDisutility() {

              @Override
              public double getLinkTravelDisutility(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }

              @Override
              public double getLinkMinimumTravelDisutility(Link link) {
                return link.getLength() / link.getFreespeed();
              }
            },
            new TravelTime() {

              @Override
              public double getLinkTravelTime(
                  Link link, double time, Person person, Vehicle vehicle) {
                return link.getLength() / link.getFreespeed();
              }
            },
            null);
    currentTimeMillis = -System.currentTimeMillis();
    for (int i = 0; i < 1e3; i++) {
      int[] ints = Sample.sampleMfromN(2, nodesArray.length);
      dijkstra.calcLeastCostPath(nodesArray[ints[0]], nodesArray[ints[1]], 3600, null, null);
    }
    currentTimeMillis += System.currentTimeMillis();
    System.out.println(currentTimeMillis);
  }