fin séance
This commit is contained in:
parent
71cee153fc
commit
3c2d58faec
4 changed files with 35 additions and 41 deletions
|
@ -1,27 +0,0 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
|
||||||
|
|
||||||
import org.insa.graphs.model.Arc;
|
|
||||||
import org.insa.graphs.model.Path;//trier tout ça
|
|
||||||
|
|
||||||
public class AStar extends DijkstraAlgorithm {
|
|
||||||
|
|
||||||
|
|
||||||
public void initLabel() {
|
|
||||||
int placeholder=0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public AStar(ShortestPathData data) {
|
|
||||||
super(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void proc1modifDijk() {
|
|
||||||
this.getInputData().getDestination();
|
|
||||||
}
|
|
||||||
|
|
||||||
//particularités de A*:
|
|
||||||
//-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
|
|
||||||
//-comment initialiser le labelstar.estim de chaque node avec cette méthode
|
|
||||||
//-comment avoir des LabelStar et non des Label
|
|
||||||
}
|
|
|
@ -1,9 +1,23 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
public class AStarAlgorithm extends DijkstraAlgorithm {
|
|
||||||
|
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Node;
|
||||||
|
|
||||||
|
public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||||
|
|
||||||
|
|
||||||
public AStarAlgorithm(ShortestPathData data) {
|
public AStarAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Label LabelTyped(Node sommet, Arc padre, float prix) {
|
||||||
|
return new LabelStar(sommet, padre, prix, (float)this.getInputData().getDestination().getPoint().distanceTo(sommet.getPoint()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//particularités de A*:
|
||||||
|
//-comment trouver la distance à vol d'oiseau entre deux nodes?--------node.getpoint().distanceTo()?
|
||||||
|
//-comment initialiser le labelstar.estim de chaque node avec cette méthode
|
||||||
|
//-comment avoir des LabelStar et non des Label
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
||||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||||
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
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.Path;
|
import org.insa.graphs.model.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;//trier tout ça
|
import java.util.Collections;//trier tout ça
|
||||||
|
@ -13,7 +14,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
public DijkstraAlgorithm(ShortestPathData data) {
|
public DijkstraAlgorithm(ShortestPathData data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Label LabelTyped(Node sommet,Arc padre, float prix){
|
||||||
|
return new Label(sommet,padre, prix);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ShortestPathSolution doRun() {
|
protected ShortestPathSolution doRun() {
|
||||||
|
|
||||||
|
@ -22,17 +27,19 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
//initialisation
|
//initialisation
|
||||||
BinaryHeap<Label> tas=new BinaryHeap<Label>();//les Label sont comparés via leurs coûts
|
BinaryHeap<Label> tas=new BinaryHeap<Label>();//les Label sont comparés via leurs coûts
|
||||||
|
|
||||||
Label[] tablabel=new Label[data.getGraph().size()];
|
Label[] tablabel=new Label[data.getGraph().size()];
|
||||||
for (int i=0;i<tablabel.length;i++) {
|
for (int i=0;i<tablabel.length;i++) {
|
||||||
tablabel[i]=new Label(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
|
tablabel[i]=LabelTyped(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
|
||||||
}//dans le tablabel[idnode] on peut retrouver node
|
}//dans le tablabel[idnode] on peut retrouver node
|
||||||
tablabel[data.getOrigin().getId()].cout=0;
|
tablabel[data.getOrigin().getId()].cout=0;
|
||||||
tas.insert(tablabel[data.getOrigin().getId()]);
|
|
||||||
|
tas.insert(tablabel[data.getOrigin().getId()]);
|
||||||
int nomark=tablabel.length;//nombre de sommets non marqués (pas optimal?)
|
int nomark=tablabel.length;//nombre de sommets non marqués (pas optimal?)
|
||||||
int x;//id du node qu'on étudie
|
int x;//id du node qu'on étudie
|
||||||
boolean arrive=false;//node de destination atteint ou pas
|
boolean arrive=false;//node de destination atteint ou pas
|
||||||
|
|
||||||
|
|
||||||
//itérations
|
//itérations
|
||||||
while (nomark>0 && !arrive && !tas.isEmpty()){
|
while (nomark>0 && !arrive && !tas.isEmpty()){
|
||||||
|
|
||||||
|
@ -56,14 +63,14 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
if (!tablabel[y].marque && data.isAllowed(arcy)) {//ligne 108 de l'excel d'avancement
|
if (!tablabel[y].marque && data.isAllowed(arcy)) {//ligne 108 de l'excel d'avancement
|
||||||
|
|
||||||
if (tablabel[y].cout>tablabel[x].cout+(float)data.getCost(arcy)) {
|
if (tablabel[y].getCost()>tablabel[x].getCost()+(float)data.getCost(arcy)) {
|
||||||
|
|
||||||
if (tablabel[y].cout!=Float.MAX_VALUE) {
|
if (tablabel[y].getCost()!=Float.MAX_VALUE) {
|
||||||
tas.remove(tablabel[y]);
|
tas.remove(tablabel[y]);
|
||||||
this.notifyNodeReached(arcy.getDestination());
|
this.notifyNodeReached(arcy.getDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
tablabel[y].cout=tablabel[x].cout+(float)data.getCost(arcy);
|
tablabel[y].cout=tablabel[x].getCost()+(float)data.getCost(arcy);
|
||||||
tablabel[y].pere=arcy;//ligne non dans le poly
|
tablabel[y].pere=arcy;//ligne non dans le poly
|
||||||
tas.insert(tablabel[y]);
|
tas.insert(tablabel[y]);
|
||||||
|
|
||||||
|
@ -86,7 +93,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
while (labelact.pere!=null) {
|
while (labelact.pere!=null) {
|
||||||
bonsarcs.add(labelact.pere);
|
bonsarcs.add(labelact.pere);
|
||||||
labelact=tablabel[labelact.pere.getOrigin().getId()];
|
labelact=tablabel[labelact.pere.getOrigin().getId()];
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse(bonsarcs);
|
Collections.reverse(bonsarcs);
|
||||||
solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));
|
solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
||||||
import org.insa.graphs.model.Arc;
|
import org.insa.graphs.model.Arc;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
|
|
||||||
public class LabelStar extends Label{
|
public class LabelStar extends Label implements Comparable<Label>{
|
||||||
|
|
||||||
protected float estim;
|
protected float estim;
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ public class LabelStar extends Label{
|
||||||
this.estim=estimation;
|
this.estim=estimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LabelStar(Node sommet, Arc padre, float prix, float estimation, boolean mark) {
|
public LabelStar(Node sommet,Arc padre, float prix, float estimation, boolean mark) {
|
||||||
super(sommet, padre, prix, mark);
|
super(sommet, padre, prix, mark);
|
||||||
this.estim=estimation;
|
this.estim=estimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getEstimation() {
|
public float getEstimation() {
|
||||||
return this.estim;//même remarque que pour son pendant dans Label
|
return this.estim;//même remarque que pour son pendant dans Label
|
||||||
}
|
}
|
||||||
|
@ -30,5 +30,5 @@ public class LabelStar extends Label{
|
||||||
this.estim=(float)destination.getPoint().distanceTo(this.sommet_courant.getPoint());
|
this.estim=(float)destination.getPoint().distanceTo(this.sommet_courant.getPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
//note: pourquoi l'icône de ce fichier de eclipse est-elle un peu différente?
|
//note: pourquoi l'icône de ce fichier dans eclipse est-elle un peu différente?
|
||||||
}
|
}
|
Loading…
Reference in a new issue