Dijkstra fixed, all tests pass
This commit is contained in:
parent
0e576e534b
commit
1e183cedf8
2 changed files with 6 additions and 11 deletions
|
@ -72,7 +72,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
// we know its origin and destination
|
||||
for (Arc arc : x.getNode().getSuccessors()) {
|
||||
|
||||
if (successor.getNode().equals(arc.getDestination())) {
|
||||
if (successor.getNode().equals(arc.getDestination()) && data.getCost(arc) == data.getCost(successorArc)) {
|
||||
// data.getcost(arc) returns a cost considering the mode chosen:
|
||||
// TIME or LENGTH
|
||||
// Similar to using getLength / getMinimumTravelTime
|
||||
|
|
|
@ -11,9 +11,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
@ -96,17 +96,12 @@ public abstract class ShortestPathAlgorithmTest {
|
|||
assert(path.getPath().isValid());
|
||||
assert(path.isFeasible());
|
||||
if (data.getMode() == Mode.LENGTH) {
|
||||
if (Math.abs( algo.getCostPath() - (double) path.getPath().getLength()) !=0) {
|
||||
System.out.println(data.getOrigin().getId());
|
||||
System.out.println(data.getDestination().getId());
|
||||
System.out.println(algo.getCostPath() + " " + path.getPath().getLength());
|
||||
}
|
||||
assert(Math.abs((float) algo.getCostPath() - path.getPath().getLength()) < 1);
|
||||
assert(Math.abs(path.getPath().getLength() - bell_path.getPath().getLength()) < 1);
|
||||
assert(Math.abs((float) algo.getCostPath() - path.getPath().getLength()) < 0.1);
|
||||
assert(Math.abs(path.getPath().getLength() - bell_path.getPath().getLength()) < 0.1);
|
||||
}
|
||||
else {
|
||||
assert(Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime()) == 0);
|
||||
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) == 0);
|
||||
assert(Math.abs(algo.getCostPath() - path.getPath().getMinimumTravelTime()) < 0.1);
|
||||
assert(Math.abs(path.getPath().getMinimumTravelTime() - bell_path.getPath().getMinimumTravelTime()) < 0.1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue