dijkstra : compiling version but not functional
This commit is contained in:
parent
f51d3a26b5
commit
6e4c4de7dd
1 changed files with 21 additions and 4 deletions
|
@ -2,11 +2,14 @@ package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
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.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
|
import org.insa.graphs.model.Path;
|
||||||
|
|
||||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
|
@ -81,7 +84,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
// Create the path ...
|
// Create the path ...
|
||||||
ArrayList<Arc> arcs_path = new ArrayList<>();
|
ArrayList<Arc> arcs_path = new ArrayList<>();
|
||||||
Label dest;
|
Label dest = labels.findMin();
|
||||||
for (Label label : labels.array) {
|
for (Label label : labels.array) {
|
||||||
if (label.getNode() == data.getDestination()){
|
if (label.getNode() == data.getDestination()){
|
||||||
dest = label;
|
dest = label;
|
||||||
|
@ -90,11 +93,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
Node current = dest.getParentNode();
|
Node current = dest.getParentNode();
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
current
|
for (Arc arc : current.getSuccessors()) {
|
||||||
}
|
if (arc.getDestination() == dest.getNode()) {
|
||||||
arc = predecessorArcs[arc.getOrigin().getId()];
|
arcs_path.add(arc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Label label : labels.array) {
|
||||||
|
if (label.getNode() == current){
|
||||||
|
dest = label;
|
||||||
|
current = label.getParentNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reverse the path...
|
||||||
|
Collections.reverse(arcs_path);
|
||||||
|
|
||||||
|
// Create the final solution.
|
||||||
|
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs_path));
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue