animator.setEastText(i, "inf");
}
animator.setEastText(selected, "0");
distances.put(handler.vertices.get(selected), 0f);
Vertex v;
queue.add(handler.vertices.get(selected));
while(!queue.isEmpty()) {
v = queue.remove(0);
System.out.println("Processing " + v.getId());
animator.setBackground(v.getId(), GREEN);
closed.add(v);
for(Edge e : v.outbound()) {
if(!closed.contains(e.getEnd())) {
if(distances.get(v) + e.getWeight() < distances.get(e.getEnd())) {
distances.put(e.getEnd(), distances.get(v) + e.getWeight());
parents.put(e.getEnd(), v);
}
animator.blink(e.getEnd().getId());
animator.setEastText(e.getEnd().getId(), distances.get(e.getEnd()) + "");
animator.setSouthText(e.getEnd().getId(), animator.getData(parents.get(e.getEnd()).getId()));
animator.blink(e.getEnd().getId());
if(queue.indexOf(e.getEnd()) == -1) {
queue.add(e.getEnd());
}
}
}
if(!handler.isDirected()) {
for(Edge e : v.inbound()) {
if(!closed.contains(e.getStart())) {
if(distances.get(v) + e.getWeight() < distances.get(e.getStart())) {
distances.put(e.getStart(), distances.get(v) + e.getWeight());
parents.put(e.getStart(), v);
}
animator.blink(e.getStart().getId());
animator.setEastText(e.getStart().getId(), distances.get(e.getStart()) + "");
animator.setSouthText(e.getStart().getId(), animator.getData(parents.get(e.getStart()).getId()));
animator.blink(e.getStart().getId());
if(queue.indexOf(e.getStart()) == -1) {
queue.add(e.getStart());
}
}
}
}
handler.repaintCanvas();
animator.sleep();
animator.sleep();
animator.setBackground(v.getId(), RED);
Collections.sort(queue, c);
}
}