Brouillon Dijkstra
This commit is contained in:
parent
83faf7dd11
commit
2a5ac7f244
2 changed files with 38 additions and 16 deletions
|
@ -1,6 +1,9 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||||
|
|
||||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
|
|
||||||
public DijkstraAlgorithm(ShortestPathData data) {
|
public DijkstraAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
|
@ -11,6 +14,38 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
final ShortestPathData data = getInputData();
|
final ShortestPathData data = getInputData();
|
||||||
ShortestPathSolution solution = null;
|
ShortestPathSolution solution = null;
|
||||||
// TODO:
|
// 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;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,6 @@ import org.insa.graphs.model.Node;
|
||||||
|
|
||||||
public class Label {
|
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?
|
//quelles valeurs de protection?
|
||||||
protected Node sommet_courant;
|
protected Node sommet_courant;
|
||||||
|
|
||||||
|
@ -24,29 +20,20 @@ public class Label {
|
||||||
|
|
||||||
//constructeur
|
//constructeur
|
||||||
public Label(Node sommet,Arc padre, int prix) {
|
public Label(Node sommet,Arc padre, int prix) {
|
||||||
if (tablabel[sommet.getId()]==null)
|
this.sommet_courant=sommet;
|
||||||
this.sommet_courant=sommet;
|
|
||||||
this.pere=padre;
|
this.pere=padre;
|
||||||
this.cout=prix;
|
this.cout=prix;
|
||||||
this.marque=false;//!\\ pas sûr que ce soit une bonne idée
|
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) {
|
public Label(Node sommet,Arc padre, int prix, boolean mark) {
|
||||||
if (tablabel[sommet.getId()]==null)
|
this.sommet_courant=sommet;
|
||||||
this.sommet_courant=sommet;
|
|
||||||
this.pere=padre;
|
this.pere=padre;
|
||||||
this.cout=prix;
|
this.cout=prix;
|
||||||
this.marque=mark;
|
this.marque=mark;
|
||||||
tablabel[sommet.getId()]=this;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Label getLabel(Node unnode) {
|
|
||||||
return tablabel[unnode.getId()];
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCost() {
|
public int getCost() {
|
||||||
return this.cout;
|
return this.cout;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue