MATSIM
MyGuidance.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.* *
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2008 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 package tutorial.programming.ownMobsimAgentUsingRouter;
20 
21 import org.matsim.api.core.v01.Id;
22 import org.matsim.api.core.v01.Scenario;
32 import org.matsim.facilities.Facility;
33 
34 import java.util.List;
35 
39 class MyGuidance {
40 
41  private final TripRouter router;
42  private final Scenario scenario;
43 
44  MyGuidance(TripRouter router, Scenario scenario) {
45  this.router = router;
46  this.scenario = scenario;
47  }
48 
49  public Id<Link> getBestOutgoingLink(Id<Link> linkId, Id<Link> destinationLinkId, double now) {
50  Person person = null; // does this work?
51  double departureTime = now;
52  String mainMode = TransportMode.car;
53  Facility<ActivityFacility> fromFacility = new LinkWrapperFacility(this.scenario.getNetwork().getLinks().get(linkId));
54  Facility<ActivityFacility> toFacility = new LinkWrapperFacility(this.scenario.getNetwork().getLinks().get(destinationLinkId));
55  List<? extends PlanElement> trip = router.calcRoute(mainMode, fromFacility, toFacility, departureTime, person);
56 
57  Leg leg = (Leg) trip.get(0); // test: either plan element 0 or 1 will be a car leg
58 
59  NetworkRoute route = (NetworkRoute) leg.getRoute();
60 
61  return route.getLinkIds().get(0); // entry number 0 should be link connected to next intersection (?)
62  }
63 
64 }
List<?extends PlanElement > calcRoute(final String mainMode, final Facility fromFacility, final Facility toFacility, final double departureTime, final Person person)
Map< Id< Link >,?extends Link > getLinks()