the methods fastest and shortest are done

This commit is contained in:
Baccari Nour 2025-03-31 10:47:38 +02:00
parent fd117fbd4d
commit ac8432dbbd
2 changed files with 32 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* <p> * <p>
* Class representing a path between nodes in a graph. * Class representing a path between nodes in a graph.
@ -25,12 +26,21 @@ public class Path {
* @return A path that goes through the given list of nodes. * @return A path that goes through the given list of nodes.
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph. * 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) public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException { throws IllegalArgumentException {
List<Arc> arcs_parcourus = new ArrayList<Arc>();
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: double time_min = Float.MAX_VALUE;
for (Node node: nodes){
arcs_parcourus=node.getSuccessors();
for (Arc arc : arcs_parcourus){
if (arc.getMinimumTravelTime()<time_min){
time_min=arc.getLength();
arcs.add(arc);
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }
@ -43,12 +53,21 @@ public class Path {
* @return A path that goes through the given list of nodes. * @return A path that goes through the given list of nodes.
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph. * 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) public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException { throws IllegalArgumentException {
List<Arc> arcs = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: List<Arc> arcs_parcourus = new ArrayList<Arc>();
float len_min = Float.MAX_VALUE;
for (Node node: nodes){
arcs_parcourus=node.getSuccessors();
for (Arc arc : arcs_parcourus){
if (arc.getLength()<len_min){
len_min=arc.getLength();
arcs.add(arc);
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }
@ -187,8 +206,14 @@ public class Path {
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public boolean isValid() { public boolean isValid() {
// TODO: boolean valid = false;
return false; boolean empty = this.isEmpty();
boolean unique_origin = ((this.getOrigin()!=null) && this.getArcs().isEmpty());
if( empty || unique_origin ){
valid=true;
}
return valid;
} }
/** /**

View file

@ -11,7 +11,7 @@
<name>be-graphes-all</name> <name>be-graphes-all</name>
<properties> <properties>
<jdk.version>17</jdk.version> <jdk.version>11</jdk.version>
<maven.compiler.source>${jdk.version}</maven.compiler.source> <maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target> <maven.compiler.target>${jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>