Brouillon Dijkstra

This commit is contained in:
Favary Pierre 2021-04-12 12:12:22 +02:00
parent 83faf7dd11
commit 2a5ac7f244
2 changed files with 38 additions and 16 deletions

View file

@ -1,7 +1,10 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.utils.BinaryHeap;
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
public DijkstraAlgorithm(ShortestPathData data) {
super(data);
}
@ -11,6 +14,38 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
final ShortestPathData data = getInputData();
ShortestPathSolution solution = null;
// TODO:
//initialisation
BinaryHeap tas=new BinaryHeap();
Label[] tablabel=new Label[data.getGraph().size()];
for (int i=0;i<tablabel.length;i++) {
tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);
}
tablabel[data.getOrigin().getId()].cout=0;
tas.insert(data.getOrigin().getId());
boolean exnonmar=true;
int min;
//itérations
while (exnonmar) {
min=tas.deleteMin();
tablabel[min].marque=true;
for (successeurs y) {
if (!tablabel[y].marque) {
if (tablabel[y].cout>tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime()) {
tablabel[y].cout=tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime();
if (exist y in tas) {
tas.update(y);
}else {
tas.insert(y);
}
}
}
}
exnonmar=false;
}
return solution;
}

View file

@ -5,10 +5,6 @@ import org.insa.graphs.model.Node;
public class Label {
//comment avoir le nombre de nodes dans le graph? (pour lier un unique label à chaque node)
private Label[] tablabel=new Label[50000000];//5000000 placeholder
//quelles valeurs de protection?
protected Node sommet_courant;
@ -24,29 +20,20 @@ public class Label {
//constructeur
public Label(Node sommet,Arc padre, int prix) {
if (tablabel[sommet.getId()]==null)
this.sommet_courant=sommet;
this.pere=padre;
this.cout=prix;
this.marque=false;//!\\ pas sûr que ce soit une bonne idée
tablabel[sommet.getId()]=this;
}
//la condition tablabel==null est un placeholder /!\
public Label(Node sommet,Arc padre, int prix, boolean mark) {
if (tablabel[sommet.getId()]==null)
this.sommet_courant=sommet;
this.pere=padre;
this.cout=prix;
this.marque=mark;
tablabel[sommet.getId()]=this;
}
public Label getLabel(Node unnode) {
return tablabel[unnode.getId()];
}
public int getCost() {
return this.cout;
}