dijkstra tests
This commit is contained in:
parent
0d6cf379f4
commit
85f52cdb6a
9 changed files with 23 additions and 10 deletions
|
@ -22,7 +22,7 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
ShortestPathSolution solution = null;
|
||||
// TODO:
|
||||
|
||||
ArrayList<Label> List_Label = new ArrayList<Label>(data.getGraph().size()); //Liste de labels
|
||||
ArrayList<LabelStar> List_Label = new ArrayList<LabelStar>(data.getGraph().size()); //Liste de labels
|
||||
BinaryHeap<Label> Tas = new BinaryHeap<Label>();
|
||||
ArrayList<Arc> Arcs = new ArrayList<Arc>();
|
||||
|
||||
|
@ -46,22 +46,24 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
|||
x = Tas.findMin();
|
||||
x.setMarque(true);
|
||||
Tas.deleteMin();
|
||||
|
||||
System.out.println("test");
|
||||
for(Arc suivant : x.getSommet().getSuccessors()){
|
||||
// Small test to check allowed roads...
|
||||
if (!data.isAllowed(suivant)) {
|
||||
continue;
|
||||
}
|
||||
System.out.println("test2");
|
||||
|
||||
Label l=List_Label.get(suivant.getDestination().getId());
|
||||
LabelStar l=List_Label.get(suivant.getDestination().getId());
|
||||
if(!l.isMarque()){
|
||||
Boolean changé = false;
|
||||
if (x.getTotalCost()+data.getCost(suivant) < l.getTotalCost()){
|
||||
changé = true;
|
||||
}
|
||||
System.out.println("test3");
|
||||
if(changé){
|
||||
if (l.getTotalCost() != Double.MAX_VALUE){
|
||||
|
||||
System.out.println("test4");
|
||||
if (l.getTotalCost() != Double.MAX_VALUE){
|
||||
Tas.remove(l);
|
||||
}
|
||||
l.setCost(x.getTotalCost()+data.getCost(suivant));
|
||||
|
|
|
@ -43,7 +43,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);
|
||||
|
@ -78,7 +77,7 @@ 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());
|
||||
|
@ -86,8 +85,18 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
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