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
|
||||
protected ShortestPathSolution doRun() {
|
||||
|
||||
|
||||
System.out.println("on est dans l'algo");
|
||||
// retrieve data from the input problem (getInputData() is inherited from the
|
||||
// parent class ShortestPathAlgorithm)
|
||||
final ShortestPathData data = getInputData();
|
||||
Graph graph = data.getGraph();
|
||||
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>();
|
||||
|
||||
// variable that will contain the solution of the shortest path problem
|
||||
ShortestPathSolution solution = null;
|
||||
|
||||
// TODO: implement the Dijkstra algorithm
|
||||
// initialisation
|
||||
int premier = 0 ;
|
||||
for(Node nod : graph.getNodes()){
|
||||
Label l = new Label(nod, false, -1, null);
|
||||
listLabel.add(nod.getId(),l );
|
||||
if (premier==0){
|
||||
Label l = new Label(nod, false, Integer.MAX_VALUE, null);
|
||||
listLabel[nod.getId()] = l ;
|
||||
if (nod.getId()==data.getOrigin().getId()){
|
||||
tas.insert(l);
|
||||
premier += 1 ;
|
||||
l.cout = 0 ;
|
||||
notifyOriginProcessed(nod);
|
||||
}
|
||||
}
|
||||
int marques = graph.size();
|
||||
|
||||
Label xl = tas.findMin();
|
||||
// iterations
|
||||
while (marques != 0){
|
||||
Label xl = tas.findMin();
|
||||
while (!tas.isEmpty() && xl.sommetCourant!= data.getDestination()){
|
||||
xl = tas.findMin();
|
||||
Node x = xl.getSommetCourant() ;
|
||||
notifyNodeMarked(x);
|
||||
xl.marque = true ;
|
||||
marques -= 1;
|
||||
for(Arc a : x.getSuccessors()){
|
||||
Node n = a.getDestination();
|
||||
if (!listLabel.get(n.getId()).getMarque()){
|
||||
int c = listLabel.get(n.getId()).cout ;
|
||||
int w = listLabel.get(x.getId()).cout + (int)a.getLength() ;
|
||||
if (c<w){
|
||||
listLabel.get(n.getId()).cout = c;
|
||||
}
|
||||
else{
|
||||
listLabel.get(n.getId()).cout = w;
|
||||
tas.insert(listLabel.get(n.getId()));
|
||||
listLabel.get(n.getId()).pere = a ;
|
||||
if(data.isAllowed(a)){
|
||||
Node n = a.getDestination();
|
||||
if (!listLabel[n.getId()].getMarque()){
|
||||
int c = listLabel[n.getId()].cout ;
|
||||
int w = listLabel[x.getId()].cout + (int)a.getLength() ;
|
||||
if (c<w){
|
||||
listLabel[n.getId()].cout = c;
|
||||
}
|
||||
else{
|
||||
if(listLabel[n.getId()].cout!=Integer.MAX_VALUE){
|
||||
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
|
||||
Arc[] predecessorArcs = new Arc[nbNodes];
|
||||
|
||||
if (predecessorArcs[data.getDestination().getId()] == null) {
|
||||
// when the algorithm terminates, return the solution that has been found
|
||||
|
||||
|
||||
if (listLabel[data.getDestination().getId()].cout == Integer.MAX_VALUE) {
|
||||
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
// The destination has been found, notify the observers.
|
||||
notifyDestinationReached(data.getDestination());
|
||||
|
||||
// Create the path from the array of predecessors...
|
||||
ArrayList<Arc> arcs = new ArrayList<>();
|
||||
Arc arc = predecessorArcs[data.getDestination().getId()];
|
||||
while (arc != null) {
|
||||
arcs.add(arc);
|
||||
arc = predecessorArcs[arc.getOrigin().getId()];
|
||||
Label nCourant = listLabel[data.getDestination().getId()];
|
||||
while (nCourant.pere!=null){
|
||||
arcs.add(nCourant.getPere());
|
||||
nCourant = listLabel[nCourant.getPere().getOrigin().getId()];
|
||||
}
|
||||
|
||||
// Reverse the path...
|
||||
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