dijkstra fonctionnel, reste à faire les tests
This commit is contained in:
parent
dd6632a1b3
commit
66e4c4e8f6
204 changed files with 507 additions and 33 deletions
|
|
@ -19,75 +19,79 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
@Override
|
@Override
|
||||||
protected ShortestPathSolution doRun() {
|
protected ShortestPathSolution doRun() {
|
||||||
|
|
||||||
|
System.out.println("on est dans l'algo");
|
||||||
// retrieve data from the input problem (getInputData() is inherited from the
|
// retrieve data from the input problem (getInputData() is inherited from the
|
||||||
// parent class ShortestPathAlgorithm)
|
// parent class ShortestPathAlgorithm)
|
||||||
final ShortestPathData data = getInputData();
|
final ShortestPathData data = getInputData();
|
||||||
Graph graph = data.getGraph();
|
Graph graph = data.getGraph();
|
||||||
final int nbNodes = graph.size();
|
final int nbNodes = graph.size();
|
||||||
ArrayList<Label> listLabel = new ArrayList<Label>(nbNodes) ;
|
// ArrayList<Label> listLabel = new ArrayList<Label>(nbNodes) ;
|
||||||
|
Label[] listLabel = new Label[nbNodes];
|
||||||
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
BinaryHeap<Label> tas = new BinaryHeap<Label>();
|
||||||
|
|
||||||
// variable that will contain the solution of the shortest path problem
|
// variable that will contain the solution of the shortest path problem
|
||||||
ShortestPathSolution solution = null;
|
ShortestPathSolution solution = null;
|
||||||
|
|
||||||
// TODO: implement the Dijkstra algorithm
|
|
||||||
// initialisation
|
// initialisation
|
||||||
int premier = 0 ;
|
|
||||||
for(Node nod : graph.getNodes()){
|
for(Node nod : graph.getNodes()){
|
||||||
Label l = new Label(nod, false, -1, null);
|
Label l = new Label(nod, false, Integer.MAX_VALUE, null);
|
||||||
listLabel.add(nod.getId(),l );
|
listLabel[nod.getId()] = l ;
|
||||||
if (premier==0){
|
if (nod.getId()==data.getOrigin().getId()){
|
||||||
tas.insert(l);
|
tas.insert(l);
|
||||||
premier += 1 ;
|
|
||||||
l.cout = 0 ;
|
l.cout = 0 ;
|
||||||
|
notifyOriginProcessed(nod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int marques = graph.size();
|
|
||||||
|
|
||||||
|
Label xl = tas.findMin();
|
||||||
// iterations
|
// iterations
|
||||||
while (marques != 0){
|
while (!tas.isEmpty() && xl.sommetCourant!= data.getDestination()){
|
||||||
Label xl = tas.findMin();
|
xl = tas.findMin();
|
||||||
Node x = xl.getSommetCourant() ;
|
Node x = xl.getSommetCourant() ;
|
||||||
|
notifyNodeMarked(x);
|
||||||
xl.marque = true ;
|
xl.marque = true ;
|
||||||
marques -= 1;
|
|
||||||
for(Arc a : x.getSuccessors()){
|
for(Arc a : x.getSuccessors()){
|
||||||
Node n = a.getDestination();
|
if(data.isAllowed(a)){
|
||||||
if (!listLabel.get(n.getId()).getMarque()){
|
Node n = a.getDestination();
|
||||||
int c = listLabel.get(n.getId()).cout ;
|
if (!listLabel[n.getId()].getMarque()){
|
||||||
int w = listLabel.get(x.getId()).cout + (int)a.getLength() ;
|
int c = listLabel[n.getId()].cout ;
|
||||||
if (c<w){
|
int w = listLabel[x.getId()].cout + (int)a.getLength() ;
|
||||||
listLabel.get(n.getId()).cout = c;
|
if (c<w){
|
||||||
}
|
listLabel[n.getId()].cout = c;
|
||||||
else{
|
}
|
||||||
listLabel.get(n.getId()).cout = w;
|
else{
|
||||||
tas.insert(listLabel.get(n.getId()));
|
if(listLabel[n.getId()].cout!=Integer.MAX_VALUE){
|
||||||
listLabel.get(n.getId()).pere = a ;
|
tas.remove(listLabel[n.getId()]);
|
||||||
|
} else {
|
||||||
|
notifyNodeReached(n);
|
||||||
|
}
|
||||||
|
listLabel[n.getId()].cout = w;
|
||||||
|
tas.insert(listLabel[n.getId()]);
|
||||||
|
listLabel[n.getId()].pere = a ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
tas.remove(xl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// when the algorithm terminates, return the solution that has been found
|
// when the algorithm terminates, return the solution that has been found
|
||||||
Arc[] predecessorArcs = new Arc[nbNodes];
|
|
||||||
|
|
||||||
if (predecessorArcs[data.getDestination().getId()] == null) {
|
if (listLabel[data.getDestination().getId()].cout == Integer.MAX_VALUE) {
|
||||||
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
// The destination has been found, notify the observers.
|
// The destination has been found, notify the observers.
|
||||||
notifyDestinationReached(data.getDestination());
|
notifyDestinationReached(data.getDestination());
|
||||||
|
|
||||||
// Create the path from the array of predecessors...
|
// Create the path from the array of predecessors...
|
||||||
ArrayList<Arc> arcs = new ArrayList<>();
|
ArrayList<Arc> arcs = new ArrayList<>();
|
||||||
Arc arc = predecessorArcs[data.getDestination().getId()];
|
Label nCourant = listLabel[data.getDestination().getId()];
|
||||||
while (arc != null) {
|
while (nCourant.pere!=null){
|
||||||
arcs.add(arc);
|
arcs.add(nCourant.getPere());
|
||||||
arc = predecessorArcs[arc.getOrigin().getId()];
|
nCourant = listLabel[nCourant.getPere().getOrigin().getId()];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse the path...
|
// Reverse the path...
|
||||||
Collections.reverse(arcs);
|
Collections.reverse(arcs);
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
be-graphes-gui/target/be-graphes-gui-0.0.1-SNAPSHOT.jar
Normal file
BIN
be-graphes-gui/target/be-graphes-gui-0.0.1-SNAPSHOT.jar
Normal file
Binary file not shown.
BIN
be-graphes-gui/target/classes/delete-icon.png
Normal file
BIN
be-graphes-gui/target/classes/delete-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
BIN
be-graphes-gui/target/classes/marker_mask.bin
Normal file
BIN
be-graphes-gui/target/classes/marker_mask.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue