forked from matsim-org/matsim-libs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move remaining Fast*-router classes to locationchoice contrib
the locationchoice is now the only place where some customized fast-routing algorithms are used.
- Loading branch information
Showing
28 changed files
with
535 additions
and
570 deletions.
There are no files selected for viewing
224 changes: 112 additions & 112 deletions
224
...re/router/AbstractFastRouterDelegate.java → ...re/router/AbstractFastRouterDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,112 @@ | ||
/* *********************************************************************** * | ||
* project: org.matsim.* | ||
* FastRouterDelegate.java | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2011 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** */ | ||
|
||
package org.matsim.core.router; | ||
|
||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Node; | ||
import org.matsim.core.router.util.LeastCostPathCalculator.Path; | ||
import org.matsim.core.router.util.NodeData; | ||
import org.matsim.core.router.util.NodeDataFactory; | ||
import org.matsim.core.router.util.PreProcessDijkstra; | ||
import org.matsim.core.router.util.RoutingNetworkLink; | ||
import org.matsim.core.router.util.RoutingNetworkNode; | ||
import org.matsim.core.utils.collections.RouterPriorityQueue; | ||
|
||
import java.util.ArrayList; | ||
|
||
/*package*/ abstract class AbstractFastRouterDelegate implements FastRouterDelegate { | ||
|
||
/*package*/ final Dijkstra dijkstra; | ||
/*package*/ final NodeDataFactory nodeDataFactory; | ||
|
||
/*package*/ AbstractFastRouterDelegate(final Dijkstra dijkstra, final NodeDataFactory nodeDataFactory) { | ||
this.dijkstra = dijkstra; | ||
this.nodeDataFactory = nodeDataFactory; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
// Some classes might override this method and do some additional stuff... | ||
} | ||
|
||
@Override | ||
public Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { | ||
ArrayList<Node> nodes = new ArrayList<>(); | ||
ArrayList<Link> links = new ArrayList<>(); | ||
|
||
nodes.add(0, ((RoutingNetworkNode) toNode).getNode()); | ||
Link tmpLink = getData(toNode).getPrevLink(); | ||
// if (tmpLink != null) { | ||
// original code | ||
// while (tmpLink.getFromNode() != fromNode) { | ||
// links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
// nodes.add(0, ((RoutingNetworkLink) tmpLink).getLink().getFromNode()); | ||
// tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); | ||
// } | ||
// links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
// nodes.add(0, ((RoutingNetworkNode) tmpLink.getFromNode()).getNode()); | ||
|
||
/* | ||
* Adapted this code to be compatible with the MultiNodeDijkstra located in | ||
* the location choice contrib. When a MultiNodeDijkstra uses multiple start nodes, | ||
* there is not a single start node that could be used to check whether | ||
* "tmpLink.getFromNode() != fromNode" is true. Instead, the start nodes do not have | ||
* a previous link. | ||
* For the regular Dikstra, this is also fine since the start node also does not have | ||
* a previous node. | ||
* cdobler, feb'14 | ||
*/ | ||
while (tmpLink != null) { | ||
links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
nodes.add(0, ((RoutingNetworkLink) tmpLink).getLink().getFromNode()); | ||
tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); | ||
} | ||
// } | ||
|
||
NodeData toNodeData = getData(toNode); | ||
return new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); | ||
} | ||
|
||
@Override | ||
public void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) { | ||
|
||
RoutingNetworkNode routingNetworkNode = (RoutingNetworkNode) outNode; | ||
NodeData outData = getData(routingNetworkNode); | ||
double currTime = outData.getTime(); | ||
double currCost = outData.getCost(); | ||
if (this.dijkstra.pruneDeadEnds) { | ||
PreProcessDijkstra.DeadEndData ddOutData = getPreProcessData(routingNetworkNode); | ||
|
||
for (Link l : routingNetworkNode.getOutLinksArray()) { | ||
this.dijkstra.relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, ddOutData); | ||
} | ||
} else { // this.pruneDeadEnds == false | ||
for (Link l : routingNetworkNode.getOutLinksArray()) { | ||
this.dijkstra.relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public PreProcessDijkstra.DeadEndData getPreProcessData(final Node n) { | ||
return ((RoutingNetworkNode) n).getDeadEndData(); | ||
} | ||
} | ||
/* *********************************************************************** * | ||
* project: org.matsim.* | ||
* FastRouterDelegate.java | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2011 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** */ | ||
|
||
package org.matsim.core.router; | ||
|
||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Node; | ||
import org.matsim.core.router.util.LeastCostPathCalculator.Path; | ||
import org.matsim.core.router.util.NodeData; | ||
import org.matsim.core.router.util.NodeDataFactory; | ||
import org.matsim.core.router.util.PreProcessDijkstra; | ||
import org.matsim.core.router.util.RoutingNetworkLink; | ||
import org.matsim.core.router.util.RoutingNetworkNode; | ||
import org.matsim.core.utils.collections.RouterPriorityQueue; | ||
|
||
import java.util.ArrayList; | ||
|
||
/*package*/ abstract class AbstractFastRouterDelegate implements FastRouterDelegate { | ||
|
||
/*package*/ final Dijkstra dijkstra; | ||
/*package*/ final NodeDataFactory nodeDataFactory; | ||
|
||
/*package*/ AbstractFastRouterDelegate(final Dijkstra dijkstra, final NodeDataFactory nodeDataFactory) { | ||
this.dijkstra = dijkstra; | ||
this.nodeDataFactory = nodeDataFactory; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
// Some classes might override this method and do some additional stuff... | ||
} | ||
|
||
@Override | ||
public Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) { | ||
ArrayList<Node> nodes = new ArrayList<>(); | ||
ArrayList<Link> links = new ArrayList<>(); | ||
|
||
nodes.add(0, ((RoutingNetworkNode) toNode).getNode()); | ||
Link tmpLink = getData(toNode).getPrevLink(); | ||
// if (tmpLink != null) { | ||
// original code | ||
// while (tmpLink.getFromNode() != fromNode) { | ||
// links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
// nodes.add(0, ((RoutingNetworkLink) tmpLink).getLink().getFromNode()); | ||
// tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); | ||
// } | ||
// links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
// nodes.add(0, ((RoutingNetworkNode) tmpLink.getFromNode()).getNode()); | ||
|
||
/* | ||
* Adapted this code to be compatible with the MultiNodeDijkstra located in | ||
* the location choice contrib. When a MultiNodeDijkstra uses multiple start nodes, | ||
* there is not a single start node that could be used to check whether | ||
* "tmpLink.getFromNode() != fromNode" is true. Instead, the start nodes do not have | ||
* a previous link. | ||
* For the regular Dikstra, this is also fine since the start node also does not have | ||
* a previous node. | ||
* cdobler, feb'14 | ||
*/ | ||
while (tmpLink != null) { | ||
links.add(0, ((RoutingNetworkLink) tmpLink).getLink()); | ||
nodes.add(0, ((RoutingNetworkLink) tmpLink).getLink().getFromNode()); | ||
tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); | ||
} | ||
// } | ||
|
||
NodeData toNodeData = getData(toNode); | ||
return new Path(nodes, links, arrivalTime - startTime, toNodeData.getCost()); | ||
} | ||
|
||
@Override | ||
public void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) { | ||
|
||
RoutingNetworkNode routingNetworkNode = (RoutingNetworkNode) outNode; | ||
NodeData outData = getData(routingNetworkNode); | ||
double currTime = outData.getTime(); | ||
double currCost = outData.getCost(); | ||
if (this.dijkstra.pruneDeadEnds) { | ||
PreProcessDijkstra.DeadEndData ddOutData = getPreProcessData(routingNetworkNode); | ||
|
||
for (Link l : routingNetworkNode.getOutLinksArray()) { | ||
this.dijkstra.relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, ddOutData); | ||
} | ||
} else { // this.pruneDeadEnds == false | ||
for (Link l : routingNetworkNode.getOutLinksArray()) { | ||
this.dijkstra.relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public PreProcessDijkstra.DeadEndData getPreProcessData(final Node n) { | ||
return ((RoutingNetworkNode) n).getDeadEndData(); | ||
} | ||
} |
122 changes: 61 additions & 61 deletions
122
.../core/router/ArrayFastRouterDelegate.java → .../core/router/ArrayFastRouterDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
/* *********************************************************************** * | ||
* project: org.matsim.* | ||
* ArrayFastRouterDelegate.java | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2012 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** */ | ||
|
||
package org.matsim.core.router; | ||
|
||
import org.matsim.api.core.v01.network.Node; | ||
import org.matsim.core.router.util.ArrayRoutingNetwork; | ||
import org.matsim.core.router.util.ArrayRoutingNetworkNode; | ||
import org.matsim.core.router.util.NodeData; | ||
import org.matsim.core.router.util.NodeDataFactory; | ||
|
||
/*package*/ class ArrayFastRouterDelegate extends AbstractFastRouterDelegate { | ||
|
||
private final ArrayRoutingNetwork network; | ||
private final NodeData[] nodeData; | ||
private boolean isInitialized = false; | ||
|
||
/*package*/ ArrayFastRouterDelegate(final Dijkstra dijkstra, final NodeDataFactory nodeDataFactory, | ||
final ArrayRoutingNetwork network) { | ||
super(dijkstra, nodeDataFactory); | ||
this.network = network; | ||
this.nodeData = new NodeData[network.getNodes().size()]; | ||
} | ||
|
||
@Override | ||
public final void initialize() { | ||
// lazy initialization | ||
if (!isInitialized) { | ||
for (Node node : this.network.getNodes().values()) { | ||
int index = ((ArrayRoutingNetworkNode) node).getArrayIndex(); | ||
this.nodeData[index] = nodeDataFactory.createNodeData(); | ||
} | ||
|
||
this.isInitialized = true; | ||
} | ||
} | ||
|
||
/* | ||
* The NodeData is taken from the array. | ||
*/ | ||
public NodeData getData(final Node n) { | ||
ArrayRoutingNetworkNode routingNetworkNode = (ArrayRoutingNetworkNode) n; | ||
return this.nodeData[routingNetworkNode.getArrayIndex()]; | ||
} | ||
/* *********************************************************************** * | ||
* project: org.matsim.* | ||
* ArrayFastRouterDelegate.java | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* copyright : (C) 2012 by the members listed in the COPYING, * | ||
* LICENSE and WARRANTY file. * | ||
* email : info at matsim dot org * | ||
* * | ||
* *********************************************************************** * | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* See also COPYING, LICENSE and WARRANTY file * | ||
* * | ||
* *********************************************************************** */ | ||
|
||
package org.matsim.core.router; | ||
|
||
import org.matsim.api.core.v01.network.Node; | ||
import org.matsim.core.router.util.ArrayRoutingNetwork; | ||
import org.matsim.core.router.util.ArrayRoutingNetworkNode; | ||
import org.matsim.core.router.util.NodeData; | ||
import org.matsim.core.router.util.NodeDataFactory; | ||
|
||
/*package*/ class ArrayFastRouterDelegate extends AbstractFastRouterDelegate { | ||
|
||
private final ArrayRoutingNetwork network; | ||
private final NodeData[] nodeData; | ||
private boolean isInitialized = false; | ||
|
||
/*package*/ ArrayFastRouterDelegate(final Dijkstra dijkstra, final NodeDataFactory nodeDataFactory, | ||
final ArrayRoutingNetwork network) { | ||
super(dijkstra, nodeDataFactory); | ||
this.network = network; | ||
this.nodeData = new NodeData[network.getNodes().size()]; | ||
} | ||
|
||
@Override | ||
public final void initialize() { | ||
// lazy initialization | ||
if (!isInitialized) { | ||
for (Node node : this.network.getNodes().values()) { | ||
int index = ((ArrayRoutingNetworkNode) node).getArrayIndex(); | ||
this.nodeData[index] = nodeDataFactory.createNodeData(); | ||
} | ||
|
||
this.isInitialized = true; | ||
} | ||
} | ||
|
||
/* | ||
* The NodeData is taken from the array. | ||
*/ | ||
public NodeData getData(final Node n) { | ||
ArrayRoutingNetworkNode routingNetworkNode = (ArrayRoutingNetworkNode) n; | ||
return this.nodeData[routingNetworkNode.getArrayIndex()]; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.