rien
このコミットが含まれているのは:
コミット
0e43c205b5
2個のファイルの変更、14行の追加、13行の削除
|
@ -24,21 +24,20 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
ArrayList<Label> List = new ArrayList<Label>(); //List de labels
|
ArrayList<Label> List = new ArrayList<Label>(); //List de labels
|
||||||
BinaryHeap<Label> Tas = new BinaryHeap<Label>();
|
BinaryHeap<Label> Tas = new BinaryHeap<Label>();
|
||||||
ArrayList<Arc> arcs = new ArrayList<Arc>();
|
ArrayList<Arc> arcs = new ArrayList<Arc>();
|
||||||
Label dest = null;
|
|
||||||
|
|
||||||
for (Node x: data.getGraph().getNodes())
|
for (Node x: data.getGraph().getNodes())
|
||||||
{
|
{
|
||||||
Label a= new Label(x,Double.MAX_VALUE,null);
|
Label a= new Label(x,Double.MAX_VALUE,null);
|
||||||
if (a.getSommet() == data.getDestination()){
|
|
||||||
dest = a;
|
|
||||||
}
|
|
||||||
List.add(a);
|
List.add(a);
|
||||||
}
|
}
|
||||||
List.get(data.getOrigin().getId()).setCost(0);
|
List.get(data.getOrigin().getId()).setCost(0);
|
||||||
Tas.insert(List.get(data.getOrigin().getId()));
|
Tas.insert(List.get(data.getOrigin().getId()));
|
||||||
int i = 1;
|
int i = 1;
|
||||||
Label x;
|
Label x;
|
||||||
while (dest.isMarque() == false){
|
Label pre = null;
|
||||||
|
|
||||||
|
while (List.get(data.getDestination().getId()).isMarque()){
|
||||||
|
//System.out.println(List);
|
||||||
x = Tas.findMin();
|
x = Tas.findMin();
|
||||||
x.setMarque(true);
|
x.setMarque(true);
|
||||||
Tas.deleteMin();
|
Tas.deleteMin();
|
||||||
|
@ -52,28 +51,30 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
changé = true;
|
changé = true;
|
||||||
}
|
}
|
||||||
if(changé){
|
if(changé){
|
||||||
if (arcs.size() < i ){
|
if (l.getCost() < data.getCost(pre.getParent())){
|
||||||
System.out.println("arc");
|
Tas.remove(pre);
|
||||||
}else if (l.getCost() < arcs.get(i-1).getLength()){
|
|
||||||
arcs.remove(i-1);
|
|
||||||
System.out.println("remove");
|
System.out.println("remove");
|
||||||
}
|
}
|
||||||
|
pre = l;
|
||||||
|
l.setCost(Math.min(l.getCost(), x.getCost()+data.getCost(suivant)));
|
||||||
Tas.insert(l);
|
Tas.insert(l);
|
||||||
l.setParent(suivant);
|
l.setParent(suivant);
|
||||||
arcs.add(suivant);
|
|
||||||
l.setMarque(true);
|
l.setMarque(true);
|
||||||
|
// System.out.println(List);
|
||||||
}
|
}
|
||||||
l.setCost(Math.min(l.getCost(), x.getCost()+data.getCost(suivant)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
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(data.getDestination());
|
||||||
System.out.println(dest.getSommet());
|
|
||||||
System.out.println(arcs);
|
System.out.println(arcs);
|
||||||
System.out.println(arcs.get(arcs.size()-1).getDestination());
|
|
||||||
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), arcs));
|
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(data.getGraph(), arcs));
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
読み込み中…
新しいイシューから参照