Merge branch 'master' of https://git.etud.insa-toulouse.fr/fofana/Be_Graphe
This commit is contained in:
當前提交
4c09642f93
共有 9 個文件被更改,包括 17 次插入 和 12 次删除
|
@ -1,13 +1,7 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
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.Arc;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
import org.insa.graphs.model.Path;
|
|
||||||
import org.insa.graphs.model.Point;
|
import org.insa.graphs.model.Point;
|
||||||
public class AStarAlgorithm extends DijkstraAlgorithm {
|
public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
}
|
}
|
||||||
Tas.insert(List_Label.get(data.getOrigin().getId()));
|
Tas.insert(List_Label.get(data.getOrigin().getId()));
|
||||||
Label x;
|
Label x;
|
||||||
|
|
||||||
while (!List_Label.get(data.getDestination().getId()).isMarque() && !Tas.isEmpty()){
|
while (!List_Label.get(data.getDestination().getId()).isMarque() && !Tas.isEmpty()){
|
||||||
x = Tas.findMin();
|
x = Tas.findMin();
|
||||||
x.setMarque(true);
|
x.setMarque(true);
|
||||||
|
@ -86,15 +85,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
Label dest =List_Label.get(data.getDestination().getId());
|
Label dest =List_Label.get(data.getDestination().getId());
|
||||||
|
|
||||||
while (dest.getParent() != null){
|
while (dest.getParent() != null){
|
||||||
Arcs.add(dest.getParent());
|
Arcs.add(dest.getParent());
|
||||||
dest = List_Label.get(dest.getParent().getOrigin().getId());
|
dest = List_Label.get(dest.getParent().getOrigin().getId());
|
||||||
}
|
}
|
||||||
Collections.reverse(Arcs);
|
Collections.reverse(Arcs);
|
||||||
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), 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;
|
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.JFrame;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
|
||||||
import org.insa.graphs.gui.drawing.Drawing;
|
import org.insa.graphs.gui.drawing.Drawing;
|
||||||
import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
||||||
import org.insa.graphs.model.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
|
@ -70,7 +71,7 @@ public class Launch {
|
||||||
|
|
||||||
// TODO: Read the path.
|
// TODO: Read the path.
|
||||||
final Path path = pathReader.readPath(graph);
|
final Path path = pathReader.readPath(graph);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
// TODO: Draw the path.
|
// TODO: Draw the path.
|
||||||
drawing.drawPath(path,Color.green);
|
drawing.drawPath(path,Color.green);
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -59,6 +59,7 @@ public class Path {
|
||||||
}
|
}
|
||||||
arcs.add(a);
|
arcs.add(a);
|
||||||
}
|
}
|
||||||
|
System.out.println(new Path(graph, arcs));
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
載入中…
Reference in a new issue