implementation createfastestPathFromNodes()
This commit is contained in:
parent
61560998b8
commit
cbca50bdd7
1 changed files with 27 additions and 3 deletions
|
|
@ -31,12 +31,36 @@ public class Path {
|
|||
throws IllegalArgumentException {
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
|
||||
for(Node node : nodes)
|
||||
if(nodes.size() == 1)
|
||||
{
|
||||
for( Arc arc : node.getSuccessors())
|
||||
return new Path(graph, nodes.get(0));
|
||||
}
|
||||
|
||||
for(int i = 0; i < nodes.size() - 1;i++)
|
||||
{
|
||||
Node origin = nodes.get(i);
|
||||
Node destination = nodes.get(i+1);
|
||||
|
||||
List<Arc> successors = origin.getSuccessors();
|
||||
Arc bestArc = null;
|
||||
float speedMin = Float.MAX_VALUE;
|
||||
for(Arc successor : successors)
|
||||
{
|
||||
|
||||
double timeSuccessor = successor.getMinimumTravelTime();
|
||||
if(successor.getDestination().equals(destination))
|
||||
{
|
||||
if (timeSuccessor < speedMin)
|
||||
{
|
||||
bestArc = successor;
|
||||
speedMin = successor.getLength();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bestArc == null)
|
||||
{
|
||||
throw new IllegalArgumentException("No arc from " + origin.getId()+ "to " + destination.getId());
|
||||
}
|
||||
arcs.add(bestArc);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue