modified: CreateFastestPath()
This commit is contained in:
parent
37bb2f5f1c
commit
44de56129e
2 changed files with 35 additions and 4 deletions
|
@ -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 {
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue