Merge branch 'master' of https://git.etud.insa-toulouse.fr/fofana/Be_Graphe
This commit is contained in:
commit
4c09642f93
9 changed files with 17 additions and 12 deletions
|
@ -1,13 +1,7 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
import org.insa.graphs.model.Point;
|
||||
public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
}
|
||||
Tas.insert(List_Label.get(data.getOrigin().getId()));
|
||||
Label x;
|
||||
|
||||
while (!List_Label.get(data.getDestination().getId()).isMarque() && !Tas.isEmpty()){
|
||||
x = Tas.findMin();
|
||||
x.setMarque(true);
|
||||
|
@ -86,15 +85,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
}
|
||||
Label dest =List_Label.get(data.getDestination().getId());
|
||||
|
||||
|
||||
while (dest.getParent() != null){
|
||||
Arcs.add(dest.getParent());
|
||||
dest = List_Label.get(dest.getParent().getOrigin().getId());
|
||||
}
|
||||
Collections.reverse(Arcs);
|
||||
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), Arcs));
|
||||
ArrayList<Node> solutionNodes = new ArrayList<Node>();
|
||||
for (Arc a : Arcs){
|
||||
solutionNodes.add(a.getOrigin());
|
||||
}
|
||||
solutionNodes.add(data.getDestination());
|
||||
Path p = Path.createShortestPathFromNodes(data.getGraph(), solutionNodes);
|
||||
Path p2 = Path.createFastestPathFromNodes(data.getGraph(), solutionNodes);
|
||||
System.out.println("shortest path : " + p.getLength());
|
||||
if (p.getLength()-solution.getPath().getLength() < 1.00){
|
||||
System.out.println("le chemin Dijkstra est le shortest");
|
||||
}
|
||||
|
||||
return solution;
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -11,6 +11,7 @@ import java.io.FileInputStream;
|
|||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
|
||||
import org.insa.graphs.gui.drawing.Drawing;
|
||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
||||
import org.insa.graphs.model.Graph;
|
||||
|
@ -70,7 +71,7 @@ public class Launch {
|
|||
|
||||
// TODO: Read the path.
|
||||
final Path path = pathReader.readPath(graph);
|
||||
|
||||
System.out.println();
|
||||
|
||||
// TODO: Draw the path.
|
||||
drawing.drawPath(path,Color.green);
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -59,6 +59,7 @@ public class Path {
|
|||
}
|
||||
arcs.add(a);
|
||||
}
|
||||
System.out.println(new Path(graph, arcs));
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue