minor improvement
This commit is contained in:
parent
a828de13ce
commit
727e1d7c2b
@ -31,4 +31,7 @@ public class Node<E> {
|
|||||||
edges.add(edge);
|
edges.add(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(DijkstraNode other) {
|
||||||
|
return this.name == other.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,12 @@ public class RouteServer implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void dijkstra(String from, String to) {
|
private void dijkstra(String from, String to) {
|
||||||
|
for (DijkstraNode<Edge> node : graph.getNodes()) {
|
||||||
|
node.setMark(false);
|
||||||
|
node.setDist(Double.POSITIVE_INFINITY);
|
||||||
|
node.setPrev(null);
|
||||||
|
}
|
||||||
|
|
||||||
Queue<DijkstraNode> pq = new PriorityQueue<DijkstraNode>();
|
Queue<DijkstraNode> pq = new PriorityQueue<DijkstraNode>();
|
||||||
DijkstraNode<Edge> start = graph.findNode(from);
|
DijkstraNode<Edge> start = graph.findNode(from);
|
||||||
DijkstraNode<Edge> goal = graph.findNode(to);
|
DijkstraNode<Edge> goal = graph.findNode(to);
|
||||||
@ -53,9 +59,7 @@ public class RouteServer implements CommandExecutor {
|
|||||||
while (!pq.isEmpty()) {
|
while (!pq.isEmpty()) {
|
||||||
DijkstraNode<Edge> current = pq.poll();
|
DijkstraNode<Edge> current = pq.poll();
|
||||||
current.setMark(true);
|
current.setMark(true);
|
||||||
// implement equals for this
|
if (current.equals(goal)) {
|
||||||
// if (current.equal(goal)) {
|
|
||||||
if (current.getName() == to) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (Edge<DijkstraNode> edge : current.getEdges()) {
|
for (Edge<DijkstraNode> edge : current.getEdges()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user