modified: CreateFastestPath()

This commit is contained in:
Nabzzz 2020-03-16 16:22:00 +01:00
parent 37bb2f5f1c
commit 44de56129e
2 changed files with 35 additions and 4 deletions

View file

@ -30,12 +30,43 @@ public class Path {
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph.
*
* @deprecated Need to be implemented.
*/
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
List<Arc> arcs = new ArrayList<Arc>();
double min_time;
Arc min_a=null;
Arc a;
boolean found;
if (nodes.size()==1)
{
return new Path(graph,nodes.get(0));
}
for(int i=0;i<nodes.size()-1;i++)
{ min_time=Double.POSITIVE_INFINITY;
found=false;
for(int j=0;j<nodes.get(i).getSuccessors().size();j++)
{
a=nodes.get(i).getSuccessors().get(j);
if(a.getDestination()==nodes.get(i+1))
{
if((a.getMinimumTravelTime())<(min_time))
{
min_time=a.getMinimumTravelTime();
min_a=a;
found=true;
}
}
}
if(!found)
{
throw new IllegalArgumentException("Cannot generate arc from these two nodes");
}
arcs.add(min_a);
}
return new Path(graph, arcs);
}
@ -51,7 +82,7 @@ public class Path {
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph.
*
* @deprecated Need to be implemented.
*/
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {