Compare commits
3 commits
3f7a1543fd
...
d6f469e32f
Author | SHA1 | Date | |
---|---|---|---|
d6f469e32f | |||
db889e56e4 | |||
4c71453889 |
1 changed files with 32 additions and 26 deletions
|
@ -15,40 +15,46 @@ import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
|
|
||||||
public class RunTimeTrial {
|
public class RunTimeTrial {
|
||||||
final static int TEST_COUNT = 100;
|
final static int TEST_COUNT_PER_MAP = 30;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Runs TEST_COUNT_PER_MAP performance test iterations for every map and
|
||||||
|
* outputs as CSV to stdout. Bellman is performed only for smaller maps.
|
||||||
|
* When running with VSC, paths are relative to the BE_Graphes directory.
|
||||||
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
final Graph graph = readGraph("./Maps/midi-pyrenees.mapgr");
|
System.out.println("N,P,D,A,B");
|
||||||
|
runTest("./Maps/midi-pyrenees.mapgr", false);
|
||||||
long totalDijkstraTime = 0;
|
runTest("./Maps/france.mapgr", false);
|
||||||
long totalAStarTime = 0;
|
runTest("./Maps/belgium.mapgr", false);
|
||||||
long totalBellmanTime = 0;
|
runTest("./Maps/bretagne.mapgr", false);
|
||||||
|
runTest("./Maps/bordeaux.mapgr", true);
|
||||||
System.err.println("N D A B");
|
runTest("./Maps/carre.mapgr", true);
|
||||||
|
runTest("./Maps/fractal.mapgr", true);
|
||||||
for (int i = 0; i < TEST_COUNT; i++) {
|
runTest("./Maps/insa.mapgr", true);
|
||||||
//System.out.println("Running time trial " + i + "/" + TEST_COUNT);
|
runTest("./Maps/toulouse.mapgr", true);
|
||||||
final ShortestPathData data = getRandomShortestPathData(graph);
|
|
||||||
|
|
||||||
ShortestPathSolution dijkstraSolution = new DijkstraAlgorithm(data).run();
|
|
||||||
ShortestPathSolution aStarSolution = new AStarAlgorithm(data).run();
|
|
||||||
//ShortestPathSolution bellmanSolution = new BellmanFordAlgorithm(data).run();
|
|
||||||
|
|
||||||
totalDijkstraTime += dijkstraSolution.getSolvingTime().toMillis();
|
|
||||||
totalAStarTime += aStarSolution.getSolvingTime().toMillis();
|
|
||||||
//totalBellmanTime += bellmanSolution.getSolvingTime().toMillis();
|
|
||||||
|
|
||||||
final int pathSize = dijkstraSolution.getPath() == null ? -1 : dijkstraSolution.getPath().getArcs().size();
|
|
||||||
System.out.println(pathSize + " "
|
|
||||||
+ dijkstraSolution.getSolvingTime().toMillis() + " "
|
|
||||||
+ aStarSolution.getSolvingTime().toMillis() + " "
|
|
||||||
//+ bellmanSolution.getSolvingTime().toMillis() + " "
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Dijkstra took " + totalDijkstraTime + " ms");
|
public static void runTest(String mapName, boolean runBellman) throws IOException {
|
||||||
System.out.println("A* took " + totalAStarTime + " ms");
|
final Graph graph = readGraph(mapName);
|
||||||
System.out.println("Bellman took " + totalBellmanTime + " ms");
|
|
||||||
|
for (int i = 0; i < TEST_COUNT_PER_MAP; i++) {
|
||||||
|
final ShortestPathData data = getRandomShortestPathData(graph);
|
||||||
|
|
||||||
|
final ShortestPathSolution dijkstraSolution = new DijkstraAlgorithm(data).run();
|
||||||
|
final ShortestPathSolution aStarSolution = new AStarAlgorithm(data).run();
|
||||||
|
final ShortestPathSolution bellmanSolution = runBellman ? new BellmanFordAlgorithm(data).run() : null;
|
||||||
|
|
||||||
|
final int pathSize = dijkstraSolution.getPath() == null ? -1 : dijkstraSolution.getPath().getArcs().size();
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
graph.size() + ","
|
||||||
|
+ pathSize + ","
|
||||||
|
+ dijkstraSolution.getSolvingTime().toMillis() + ","
|
||||||
|
+ aStarSolution.getSolvingTime().toMillis() + ","
|
||||||
|
+ (runBellman ? bellmanSolution.getSolvingTime().toMillis() : "")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,10 +65,10 @@ public class RunTimeTrial {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ArcInspector getRandomArcFilter() {
|
private static ArcInspector getRandomArcFilter() {
|
||||||
final Random rand = new Random();
|
// final Random rand = new Random();
|
||||||
final List<ArcInspector> filters = ArcInspectorFactory.getAllFilters();
|
final List<ArcInspector> filters = ArcInspectorFactory.getAllFilters();
|
||||||
//return filters.get(Math.abs(rand.nextInt()) % filters.size());
|
//return filters.get(Math.abs(rand.nextInt()) % filters.size());
|
||||||
return filters.get(0);
|
return filters.get(0); // all arcs
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ShortestPathData getRandomShortestPathData(Graph graph) {
|
private static ShortestPathData getRandomShortestPathData(Graph graph) {
|
||||||
|
|
Loading…
Reference in a new issue