MATSIM
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
org.matsim.utils.leastcostpathtree.LeastCostPathTree Class Reference

Classes

class  ComparatorCost
 
class  NodeData
 

Public Member Functions

 LeastCostPathTree (TravelTime tt, TravelDisutility tc)
 
void calculate (final Network network, final Node origin, final double time)
 
final IdMap< Node, NodeDatagetTree ()
 
final Node getOrigin ()
 
final double getDepartureTime ()
 

Static Public Member Functions

static void main (String[] args)
 

Protected Member Functions

void additionalComputationsHook (Link link, double currTime)
 

Private Member Functions

void relaxNode (final Node n, PriorityQueue< Node > pendingNodes)
 

Private Attributes

Node origin1 = null
 
double dTime = Double.NaN
 
final TravelTime ttFunction
 
final TravelDisutility tcFunction
 
IdMap< Node, NodeDatanodeData = null
 
final Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType())
 
final Person PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class))
 

Detailed Description

Calculates a least-cost-path tree using Dijkstra's algorithm for calculating a shortest-path tree, given a node as root of the tree.

Author
balmermi, mrieser

Definition at line 53 of file LeastCostPathTree.java.

Constructor & Destructor Documentation

◆ LeastCostPathTree()

org.matsim.utils.leastcostpathtree.LeastCostPathTree.LeastCostPathTree ( TravelTime  tt,
TravelDisutility  tc 
)

Member Function Documentation

◆ calculate()

void org.matsim.utils.leastcostpathtree.LeastCostPathTree.calculate ( final Network  network,
final Node  origin,
final double  time 
)

Definition at line 78 of file LeastCostPathTree.java.

References org.matsim.api.core.v01.Identifiable< T >.getId(), org.matsim.api.core.v01.IdMap< T, V >.put(), and org.matsim.utils.leastcostpathtree.LeastCostPathTree.relaxNode().

78  {
79  this.origin1 = origin;
80  this.dTime = time;
81 
82  this.nodeData = new IdMap<>(Node.class);
83  NodeData d = new NodeData();
84  d.time = time;
85  d.cost = 0;
86  this.nodeData.put(origin.getId(), d);
87 
88  ComparatorCost comparator = new ComparatorCost(this.nodeData);
89  PriorityQueue<Node> pendingNodes = new PriorityQueue<>(500, comparator);
90  relaxNode(origin, pendingNodes);
91  while (!pendingNodes.isEmpty()) {
92  Node n = pendingNodes.poll();
93  relaxNode(n, pendingNodes);
94  }
95  }
void relaxNode(final Node n, PriorityQueue< Node > pendingNodes)
Here is the call graph for this function:

◆ getTree()

final IdMap<Node, NodeData> org.matsim.utils.leastcostpathtree.LeastCostPathTree.getTree ( )

Definition at line 152 of file LeastCostPathTree.java.

References org.matsim.utils.leastcostpathtree.LeastCostPathTree.nodeData.

152  {
153  return this.nodeData;
154  }

◆ getOrigin()

final Node org.matsim.utils.leastcostpathtree.LeastCostPathTree.getOrigin ( )
Returns
Returns the root of the calculated tree, or null if no tree was calculated yet.

Definition at line 159 of file LeastCostPathTree.java.

References org.matsim.utils.leastcostpathtree.LeastCostPathTree.origin1.

◆ getDepartureTime()

final double org.matsim.utils.leastcostpathtree.LeastCostPathTree.getDepartureTime ( )

◆ relaxNode()

void org.matsim.utils.leastcostpathtree.LeastCostPathTree.relaxNode ( final Node  n,
PriorityQueue< Node pendingNodes 
)
private

Definition at line 171 of file LeastCostPathTree.java.

References org.matsim.utils.leastcostpathtree.LeastCostPathTree.additionalComputationsHook(), org.matsim.api.core.v01.IdMap< T, V >.get(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.NodeData.getCost(), org.matsim.api.core.v01.Identifiable< T >.getId(), org.matsim.core.router.util.TravelDisutility.getLinkTravelDisutility(), org.matsim.core.router.util.TravelTime.getLinkTravelTime(), org.matsim.api.core.v01.network.Node.getOutLinks(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.NodeData.getTime(), and org.matsim.api.core.v01.IdMap< T, V >.put().

Referenced by org.matsim.utils.leastcostpathtree.LeastCostPathTree.calculate().

171  {
172  NodeData nData = nodeData.get(n.getId());
173  double currTime = nData.getTime();
174  double currCost = nData.getCost();
175  for (Link l : n.getOutLinks().values()) {
176  Node nn = l.getToNode();
177  NodeData nnData = nodeData.get(nn.getId());
178  if (nnData == null) {
179  nnData = new NodeData();
180  this.nodeData.put(nn.getId(), nnData);
181  }
182  double visitCost = currCost + tcFunction.getLinkTravelDisutility(l, currTime, PERSON, VEHICLE);
183  double visitTime = currTime + ttFunction.getLinkTravelTime(l, currTime, PERSON, VEHICLE);
184 
185 
186  if (visitCost < nnData.getCost()) {
187  pendingNodes.remove(nn);
188  nnData.visit(n.getId(), visitCost, visitTime);
189  additionalComputationsHook( l, currTime ) ;
190  pendingNodes.add(nn);
191  }
192  }
193  }
double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle)
double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle)
void additionalComputationsHook(Link link, double currTime)
Here is the call graph for this function:

◆ additionalComputationsHook()

void org.matsim.utils.leastcostpathtree.LeastCostPathTree.additionalComputationsHook ( Link  link,
double  currTime 
)
protected

Definition at line 195 of file LeastCostPathTree.java.

Referenced by org.matsim.utils.leastcostpathtree.LeastCostPathTree.relaxNode().

195  {
196  // left empty for inheritance
197  }

◆ main()

static void org.matsim.utils.leastcostpathtree.LeastCostPathTree.main ( String []  args)
static

Definition at line 203 of file LeastCostPathTree.java.

References org.matsim.api.core.v01.TransportMode.car, org.matsim.api.core.v01.Id< T >.create(), org.matsim.core.config.ConfigUtils.createConfig(), org.matsim.core.scenario.ScenarioUtils.createScenario(), org.matsim.api.core.v01.IdMap< T, V >.entrySet(), org.matsim.core.scenario.MutableScenario.getConfig(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.NodeData.getCost(), org.matsim.core.trafficmonitoring.TravelTimeCalculator.getLinkTravelTimes(), org.matsim.core.scenario.MutableScenario.getNetwork(), org.matsim.api.core.v01.network.Network.getNodes(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.NodeData.getPrevNodeId(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.NodeData.getTime(), org.matsim.utils.leastcostpathtree.LeastCostPathTree.LeastCostPathTree(), and org.matsim.core.config.Config.travelTimeCalculator().

203  {
204  MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig());
205  Network network = scenario.getNetwork();
206  new MatsimNetworkReader(scenario.getNetwork()).readFile("../../input/network.xml");
207 
208  TravelTimeCalculator ttc = new TravelTimeCalculator(network, 60, 30 * 3600, scenario.getConfig().travelTimeCalculator());
209  LeastCostPathTree st = new LeastCostPathTree(ttc.getLinkTravelTimes(), new RandomizingTimeDistanceTravelDisutilityFactory( TransportMode.car, scenario.getConfig() ).createTravelDisutility(ttc.getLinkTravelTimes()));
210  Node origin = network.getNodes().get(Id.create(1, Node.class));
211  st.calculate(network, origin, 8*3600);
212  IdMap<Node, NodeData> tree = st.getTree();
213  for (Map.Entry<Id<Node>, NodeData> e : tree.entrySet()) {
214  Id<Node> id = e.getKey();
215  NodeData d = e.getValue();
216  if (d.getPrevNodeId() != null) {
217  System.out.println(id + "\t" + d.getTime() + "\t" + d.getCost() + "\t" + d.getPrevNodeId());
218  } else {
219  System.out.println(id + "\t" + d.getTime() + "\t" + d.getCost() + "\t" + "0");
220  }
221  }
222  }
LeastCostPathTree(TravelTime tt, TravelDisutility tc)
Here is the call graph for this function:

Member Data Documentation

◆ origin1

Node org.matsim.utils.leastcostpathtree.LeastCostPathTree.origin1 = null
private

◆ dTime

double org.matsim.utils.leastcostpathtree.LeastCostPathTree.dTime = Double.NaN
private

◆ ttFunction

final TravelTime org.matsim.utils.leastcostpathtree.LeastCostPathTree.ttFunction
private

Definition at line 62 of file LeastCostPathTree.java.

◆ tcFunction

final TravelDisutility org.matsim.utils.leastcostpathtree.LeastCostPathTree.tcFunction
private

Definition at line 63 of file LeastCostPathTree.java.

◆ nodeData

IdMap<Node, NodeData> org.matsim.utils.leastcostpathtree.LeastCostPathTree.nodeData = null
private

◆ VEHICLE

final Vehicle org.matsim.utils.leastcostpathtree.LeastCostPathTree.VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType())
private

Definition at line 66 of file LeastCostPathTree.java.

◆ PERSON

final Person org.matsim.utils.leastcostpathtree.LeastCostPathTree.PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class))
private

Definition at line 67 of file LeastCostPathTree.java.


The documentation for this class was generated from the following file: