Tests and other minor improvements
This commit is contained in:
parent
ba2f4fdf3d
commit
db095f9ea9
4 changed files with 15 additions and 16 deletions
|
@ -47,12 +47,11 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
|
||||||
int dataMaxSpeed = data.getMaximumSpeed();
|
int dataMaxSpeed = data.getMaximumSpeed();
|
||||||
int graphMaxSpeed = data.getGraph().getGraphInformation().getMaximumSpeed();
|
int graphMaxSpeed = data.getGraph().getGraphInformation().getMaximumSpeed();
|
||||||
if (dataMaxSpeed == NO_MAXIMUM_SPEED && graphMaxSpeed == NO_MAXIMUM_SPEED)
|
if (dataMaxSpeed == NO_MAXIMUM_SPEED && graphMaxSpeed == NO_MAXIMUM_SPEED)
|
||||||
return 1000;
|
return (int) (130/3.6);
|
||||||
if (dataMaxSpeed != NO_MAXIMUM_SPEED && graphMaxSpeed != NO_MAXIMUM_SPEED)
|
if (dataMaxSpeed != NO_MAXIMUM_SPEED && graphMaxSpeed != NO_MAXIMUM_SPEED)
|
||||||
return (int) (Math.min(dataMaxSpeed, graphMaxSpeed)/3.6);
|
return (int) (Math.min(dataMaxSpeed, graphMaxSpeed)/3.6);
|
||||||
if (dataMaxSpeed != NO_MAXIMUM_SPEED)
|
if (dataMaxSpeed != NO_MAXIMUM_SPEED)
|
||||||
return (int) (dataMaxSpeed/3.6);
|
return (int) (dataMaxSpeed/3.6);
|
||||||
return (int) (graphMaxSpeed/3.6);
|
return (int) (graphMaxSpeed/3.6);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,21 +54,22 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
heap.insert(labels.get(originId));
|
heap.insert(labels.get(originId));
|
||||||
notifyOriginProcessed(origin);
|
notifyOriginProcessed(origin);
|
||||||
|
|
||||||
// int iterationCounter = 0;
|
|
||||||
Node destination = data.getDestination();
|
Node destination = data.getDestination();
|
||||||
Node currentNode = null;
|
Node currentNode = null;
|
||||||
|
double previousCost = 0;
|
||||||
|
|
||||||
while (!heap.isEmpty() && (currentNode == null || !currentNode.equals(destination))) {
|
while (!heap.isEmpty() && (currentNode == null || !currentNode.equals(destination))) {
|
||||||
// iterationCounter++;
|
|
||||||
// Get the node with the minimum cost
|
// Get the node with the minimum cost
|
||||||
Label currentLabel = heap.deleteMin();
|
Label currentLabel = heap.deleteMin();
|
||||||
currentLabel.mark();
|
currentLabel.mark();
|
||||||
currentNode = currentLabel.getNode();
|
currentNode = currentLabel.getNode();
|
||||||
|
|
||||||
// System.out.printf("Label marked : cost = %f; %d succesors; heap valid = %b \n",
|
/*
|
||||||
// currentLabel.getCost(),
|
// Debug
|
||||||
// currentNode.getSuccessors().size(),
|
assert(((BinaryHeap<Label>) heap).isValid());
|
||||||
// ((BinaryHeap<Label>)heap).isValid());
|
assert(currentLabel.getTotalCost() >= previousCost);
|
||||||
|
previousCost = currentLabel.getCost();
|
||||||
|
*/
|
||||||
|
|
||||||
for (Arc arc : currentNode.getSuccessors()) {
|
for (Arc arc : currentNode.getSuccessors()) {
|
||||||
Node dest = arc.getDestination();
|
Node dest = arc.getDestination();
|
||||||
|
@ -110,9 +111,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
currentLabel = labels.get(arc.getOrigin().getId());
|
currentLabel = labels.get(arc.getOrigin().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.printf("Nombre d'arcs du plus court chemin : %d\n", path.size());
|
|
||||||
// System.out.printf("Nombre d'itérations : %d\n", iterationCounter);
|
|
||||||
|
|
||||||
Collections.reverse(path);
|
Collections.reverse(path);
|
||||||
|
|
||||||
return new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, new Path(data.getGraph(), path));
|
return new ShortestPathSolution(data, AbstractSolution.Status.OPTIMAL, new Path(data.getGraph(), path));
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class AStarAlgorithmTest extends ShortestPathTest {
|
public class AStarAlgorithmTest extends ShortestPathTest {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,27 +18,27 @@ import java.util.List;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public abstract class ShortestPathTest {
|
public abstract class ShortestPathTest {
|
||||||
String[] maps = {
|
private final String[] maps = {
|
||||||
"/home/yohan/Documents/etudes/be-graphes/maps/carre.mapgr",
|
"/home/yohan/Documents/etudes/be-graphes/maps/carre.mapgr",
|
||||||
"/home/yohan/Documents/etudes/be-graphes/maps/insa.mapgr",
|
"/home/yohan/Documents/etudes/be-graphes/maps/insa.mapgr",
|
||||||
"/home/yohan/Documents/etudes/be-graphes/maps/toulouse.mapgr",
|
"/home/yohan/Documents/etudes/be-graphes/maps/toulouse.mapgr",
|
||||||
"/home/yohan/Documents/etudes/be-graphes/maps/guadeloupe.mapgr",
|
"/home/yohan/Documents/etudes/be-graphes/maps/guadeloupe.mapgr",
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] origIndexes = {
|
private final int[] origIndexes = {
|
||||||
22,
|
22,
|
||||||
553,
|
553,
|
||||||
25643,
|
25643,
|
||||||
6187,
|
6187,
|
||||||
};
|
};
|
||||||
int[] destIndexes = {
|
private final int[] destIndexes = {
|
||||||
15,
|
15,
|
||||||
111,
|
111,
|
||||||
17402,
|
17402,
|
||||||
15025,
|
15025,
|
||||||
};
|
};
|
||||||
|
|
||||||
ArcInspector[] arcInspectors = {
|
private final ArcInspector[] arcInspectors = {
|
||||||
ArcInspectorFactory.getAllFilters().get(0),
|
ArcInspectorFactory.getAllFilters().get(0),
|
||||||
ArcInspectorFactory.getAllFilters().get(2),
|
ArcInspectorFactory.getAllFilters().get(2),
|
||||||
};
|
};
|
||||||
|
@ -74,6 +74,7 @@ public abstract class ShortestPathTest {
|
||||||
// Check result against Bellman Ford algorithm (except for the square map or there may be several paths with the same cost)
|
// Check result against Bellman Ford algorithm (except for the square map or there may be several paths with the same cost)
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
assertEquals(sol.getPath(), oracle.getPath());
|
assertEquals(sol.getPath(), oracle.getPath());
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ public abstract class ShortestPathTest {
|
||||||
assertTrue(sol.isFeasible());
|
assertTrue(sol.isFeasible());
|
||||||
assertTrue(sol.getPath().isValid());
|
assertTrue(sol.getPath().isValid());
|
||||||
assertEquals(sol.getPath().getLength(), 0, 1e-5);
|
assertEquals(sol.getPath().getLength(), 0, 1e-5);
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +95,7 @@ public abstract class ShortestPathTest {
|
||||||
ShortestPathData data = createData(maps[3], arcInspector, origIndexes[3], destIndexes[3]);
|
ShortestPathData data = createData(maps[3], arcInspector, origIndexes[3], destIndexes[3]);
|
||||||
ShortestPathSolution sol = runShortestPathAlgo(data);
|
ShortestPathSolution sol = runShortestPathAlgo(data);
|
||||||
assertFalse(sol.isFeasible());
|
assertFalse(sol.isFeasible());
|
||||||
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue