rien
This commit is contained in:
parent
f69318c33d
commit
0e43c205b5
2 changed files with 14 additions and 13 deletions
|
@ -24,21 +24,20 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
ArrayList<Label> List = new ArrayList<Label>(); //List de labels
|
||||
BinaryHeap<Label> Tas = new BinaryHeap<Label>();
|
||||
ArrayList<Arc> arcs = new ArrayList<Arc>();
|
||||
Label dest = null;
|
||||
|
||||
for (Node x: data.getGraph().getNodes())
|
||||
{
|
||||
Label a= new Label(x,Double.MAX_VALUE,null);
|
||||
if (a.getSommet() == data.getDestination()){
|
||||
dest = a;
|
||||
}
|
||||
List.add(a);
|
||||
}
|
||||
List.get(data.getOrigin().getId()).setCost(0);
|
||||
Tas.insert(List.get(data.getOrigin().getId()));
|
||||
int i = 1;
|
||||
Label x;
|
||||
while (dest.isMarque() == false){
|
||||
Label pre = null;
|
||||
|
||||
while (List.get(data.getDestination().getId()).isMarque()){
|
||||
//System.out.println(List);
|
||||
x = Tas.findMin();
|
||||
x.setMarque(true);
|
||||
Tas.deleteMin();
|
||||
|
@ -52,28 +51,30 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
changé = true;
|
||||
}
|
||||
if(changé){
|
||||
if (arcs.size() < i ){
|
||||
System.out.println("arc");
|
||||
}else if (l.getCost() < arcs.get(i-1).getLength()){
|
||||
arcs.remove(i-1);
|
||||
if (l.getCost() < data.getCost(pre.getParent())){
|
||||
Tas.remove(pre);
|
||||
System.out.println("remove");
|
||||
}
|
||||
pre = l;
|
||||
l.setCost(Math.min(l.getCost(), x.getCost()+data.getCost(suivant)));
|
||||
Tas.insert(l);
|
||||
l.setParent(suivant);
|
||||
arcs.add(suivant);
|
||||
l.setMarque(true);
|
||||
// System.out.println(List);
|
||||
}
|
||||
l.setCost(Math.min(l.getCost(), x.getCost()+data.getCost(suivant)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
Label dest =List.get(data.getDestination().getId());
|
||||
while (dest.getParent() != null){
|
||||
arcs.add(dest.getParent());
|
||||
dest = List.get(dest.getParent().getOrigin().getId());
|
||||
}
|
||||
System.out.println(data.getDestination());
|
||||
System.out.println(dest.getSommet());
|
||||
System.out.println(arcs);
|
||||
System.out.println(arcs.get(arcs.size()-1).getDestination());
|
||||
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), arcs));
|
||||
return solution;
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue