This commit is contained in:
El Haji Fofana 2023-05-18 18:14:08 +02:00
當前提交 4c09642f93
共有 9 個文件被更改,包括 17 次插入12 次删除

查看文件

@ -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;
}
}

查看文件

@ -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);

查看文件

@ -59,6 +59,7 @@ public class Path {
}
arcs.add(a);
}
System.out.println(new Path(graph, arcs));
return new Path(graph, arcs);
}