fini la partie de creation shortest et fastest path
This commit is contained in:
parent
ba0702c092
commit
e52af9e118
1 changed files with 84 additions and 7 deletions
|
@ -30,12 +30,80 @@ public class Path {
|
|||
*/
|
||||
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
||||
throws IllegalArgumentException {
|
||||
if (nodes.size() == 1) {
|
||||
Node node = nodes.get(0);
|
||||
return new Path(graph, node);
|
||||
|
||||
}
|
||||
|
||||
if (nodes.size() == 0) {
|
||||
Node node = null;
|
||||
return new Path(graph, node);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
// TODO:
|
||||
|
||||
// Node leorigin = nodes.get(0);
|
||||
Node ledest = nodes.get(nodes.size() - 1);
|
||||
boolean hsein = true;
|
||||
int i = 0;
|
||||
|
||||
while (hsein && i < nodes.size()) {
|
||||
double vitessemin = Float.MAX_VALUE;
|
||||
if (!(nodes.get(i).hasSuccessors()) && nodes.get(i) != ledest) {
|
||||
hsein = false;
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
}
|
||||
boolean bonsuccesseur = false;
|
||||
// parcours de la liste des successeurs verification destinataire
|
||||
if (nodes.get(i) != ledest) {
|
||||
for (int k = 0; k < nodes.get(i).getSuccessors().size(); k++) {
|
||||
if (i < nodes.size()) {
|
||||
if (nodes.get(i).getSuccessors().get(k)
|
||||
.getDestination() == nodes.get(i + 1)) {
|
||||
bonsuccesseur = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!bonsuccesseur) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
// si on n'a pas le bonsuccesseur on doit throw un
|
||||
// IllegalArgumentException
|
||||
|
||||
// on continue si on a le bonsuccesseur sinon on a une exception
|
||||
if (bonsuccesseur) {
|
||||
Arc arcajouter = null;
|
||||
for (int j = 0; j < nodes.get(i).getSuccessors().size(); j++) {
|
||||
if (nodes.get(i).getSuccessors().get(j)
|
||||
.getDestination() == nodes.get(i + 1)) {
|
||||
if (nodes.get(i).getSuccessors().get(j)
|
||||
.getMinimumTravelTime() < vitessemin) {
|
||||
vitessemin = nodes.get(i).getSuccessors().get(j)
|
||||
.getMinimumTravelTime();
|
||||
arcajouter = nodes.get(i).getSuccessors().get(j);
|
||||
// arcs.add(arcajouter);
|
||||
// System.out.println(arcs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
arcs.add(arcajouter);
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new path that goes through the given list of nodes (in order), choosing
|
||||
|
@ -56,6 +124,12 @@ public class Path {
|
|||
|
||||
}
|
||||
|
||||
|
||||
if (nodes.size() == 0) {
|
||||
Node node = null;
|
||||
return new Path(graph, node);
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
|
||||
|
@ -70,9 +144,7 @@ public class Path {
|
|||
float longueurmin = Float.MAX_VALUE;
|
||||
if (!(nodes.get(i).hasSuccessors()) && nodes.get(i) != ledest) {
|
||||
hsein = false;
|
||||
throw new IllegalArgumentException(
|
||||
"The path is invalid: node " + nodes.get(i)
|
||||
+ " has no successors but is not the destination.");
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
}
|
||||
boolean bonsuccesseur = false;
|
||||
|
@ -87,8 +159,13 @@ public class Path {
|
|||
}
|
||||
|
||||
}
|
||||
if (!bonsuccesseur) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
// si on n'a pas le bonsuccesseur on doit throw un
|
||||
// IllegalArgumentException
|
||||
|
||||
// on continue si on a le bonsuccesseur sinon on a une exception
|
||||
if (bonsuccesseur) {
|
||||
|
@ -175,7 +252,7 @@ public class Path {
|
|||
* Create a new path containing a single node.
|
||||
*
|
||||
* @param graph Graph containing the path.
|
||||
* @param node Single node of the path.
|
||||
* @param node Single node of the path. return new Path(graph, arcs); }
|
||||
*/
|
||||
public Path(Graph graph, Node node) {
|
||||
this.graph = graph;
|
||||
|
|
Loading…
Reference in a new issue