the methods fastest and shortest are done
This commit is contained in:
parent
fd117fbd4d
commit
ac8432dbbd
2 changed files with 32 additions and 7 deletions
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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.
|
||||
* @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_parcourus = 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);
|
||||
}
|
||||
|
||||
|
@ -43,12 +53,21 @@ public class Path {
|
|||
* @return A path that goes through the given list of nodes.
|
||||
* @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 {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -187,8 +206,14 @@ public class Path {
|
|||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
// TODO:
|
||||
return false;
|
||||
boolean valid = false;
|
||||
boolean empty = this.isEmpty();
|
||||
boolean unique_origin = ((this.getOrigin()!=null) && this.getArcs().isEmpty());
|
||||
|
||||
if( empty || unique_origin ){
|
||||
valid=true;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<name>be-graphes-all</name>
|
||||
|
||||
<properties>
|
||||
<jdk.version>17</jdk.version>
|
||||
<jdk.version>11</jdk.version>
|
||||
<maven.compiler.source>${jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
|
Loading…
Reference in a new issue