implementation createfastestPathFromNodes()

This commit is contained in:
Thior Youssouf-Ben-Abdallah 2025-04-13 16:00:51 +02:00
parent 61560998b8
commit cbca50bdd7

View file

@ -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);
}