This commit is contained in:
Hamdi Soltan 2026-04-14 18:24:08 +02:00
parent 76b121ac6f
commit b059a07cf1
2 changed files with 100 additions and 10 deletions

21
.gitignore vendored Normal file
View file

@ -0,0 +1,21 @@
# OS specific files and folders
.DS_Store
# Java specific files and folders
bin
target
doc
*.jar
.settings
.classpath
.vscode
# Editor specific files and folders
*~
.project
# Project specific files and folders
*.mapfg
*.mapgr
*.path
*.tgz

View file

@ -30,7 +30,22 @@ public class Path {
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 = new ArrayList<Arc>(); List<Arc> arcs = new ArrayList<Arc>();
// TODO: if (nodes.size() <= 2){
throw new IllegalArgumentException();
}else{
for (int j = 0; j < nodes.size(); j++){
Node premier = nodes.get(j);
List<Arc> suc = premier.getSuccessors();
Arc elu = suc.get(0);
for (int i=0; i < suc.size(); i++){
if ( suc.get(i).getMinimumTravelTime() <= elu.getMinimumTravelTime()){
elu = suc.get(i);
}
arcs.add(elu);
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }
@ -48,7 +63,24 @@ public class Path {
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: if (nodes.size() <= 2){
throw new IllegalArgumentException();
}else{
for (int j = 0; j < nodes.size(); j++){
Node premier = nodes.get(j);
List<Arc> suc = premier.getSuccessors();
Arc elu = suc.get(0);
for (int i=0; i < suc.size(); i++){
if ( suc.get(i).getLength() <= elu.getLength()){
elu = suc.get(i);
}
arcs.add(elu);
}
}
}
return new Path(graph, arcs); return new Path(graph, arcs);
} }
@ -186,9 +218,33 @@ public class Path {
* @return true if the path is valid, false otherwise. * @return true if the path is valid, false otherwise.
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public boolean isValid() { public boolean isValid() {
// TODO: if(this.arcs.isEmpty()){
return true ;
}
if ( this.graph.getNodes().size() <= 1 ){
return true ;
}
Node origin = this.graph.getNodes().getFirst(); // à revoir ( on prend deux arcs quelconque et compare )
List<Arc> firstSucs = origin.getSuccessors();
List<Node> destFirstArc = new ArrayList<>() ;
for( Arc fSuc : firstSucs){
destFirstArc.add(fSuc.getDestination()) ;
}
for (Node secondNode : destFirstArc){
List<Arc> secondSucs = secondNode.getSuccessors();
for (Arc sSuc : secondSucs){
if ( sSuc.getDestination() == origin){
return true ;
}
}
}
return false; return false;
} }
/** /**
@ -198,8 +254,12 @@ public class Path {
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public float getLength() { public float getLength() {
// TODO: float sum = 0;
return 0; for(Arc a: this.arcs){
sum += a.getLength();
}
return sum;
} }
/** /**
@ -211,8 +271,12 @@ public class Path {
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public double getTravelTime(double speed) { public double getTravelTime(double speed) {
// TODO: double sum = 0;
return 0; for(Arc a: this.arcs){
sum += a.getTravelTime(speed);
}
return sum;
} }
/** /**
@ -223,8 +287,13 @@ public class Path {
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public double getMinimumTravelTime() { public double getMinimumTravelTime() {
// TODO: double sum = 0;
return 0; for(Arc a: this.arcs){
sum += a.getMinimumTravelTime();
}
return sum;
} }
} }