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;
|
||||
|
||||
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 {
|
||||
final Graph graph = readGraph("./Maps/midi-pyrenees.mapgr");
|
||||
System.out.println("N,P,D,A,B");
|
||||
runTest("./Maps/midi-pyrenees.mapgr", false);
|
||||
runTest("./Maps/france.mapgr", false);
|
||||
runTest("./Maps/belgium.mapgr", false);
|
||||
runTest("./Maps/bretagne.mapgr", false);
|
||||
runTest("./Maps/bordeaux.mapgr", true);
|
||||
runTest("./Maps/carre.mapgr", true);
|
||||
runTest("./Maps/fractal.mapgr", true);
|
||||
runTest("./Maps/insa.mapgr", true);
|
||||
runTest("./Maps/toulouse.mapgr", true);
|
||||
}
|
||||
|
||||
long totalDijkstraTime = 0;
|
||||
long totalAStarTime = 0;
|
||||
long totalBellmanTime = 0;
|
||||
public static void runTest(String mapName, boolean runBellman) throws IOException {
|
||||
final Graph graph = readGraph(mapName);
|
||||
|
||||
System.err.println("N D A B");
|
||||
|
||||
for (int i = 0; i < TEST_COUNT; i++) {
|
||||
//System.out.println("Running time trial " + i + "/" + TEST_COUNT);
|
||||
for (int i = 0; i < TEST_COUNT_PER_MAP; i++) {
|
||||
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 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(pathSize + " "
|
||||
+ dijkstraSolution.getSolvingTime().toMillis() + " "
|
||||
+ aStarSolution.getSolvingTime().toMillis() + " "
|
||||
//+ bellmanSolution.getSolvingTime().toMillis() + " "
|
||||
|
||||
System.out.println(
|
||||
graph.size() + ","
|
||||
+ pathSize + ","
|
||||
+ dijkstraSolution.getSolvingTime().toMillis() + ","
|
||||
+ aStarSolution.getSolvingTime().toMillis() + ","
|
||||
+ (runBellman ? bellmanSolution.getSolvingTime().toMillis() : "")
|
||||
);
|
||||
}
|
||||
|
||||
System.out.println("Dijkstra took " + totalDijkstraTime + " ms");
|
||||
System.out.println("A* took " + totalAStarTime + " ms");
|
||||
System.out.println("Bellman took " + totalBellmanTime + " ms");
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,10 +65,10 @@ public class RunTimeTrial {
|
|||
}
|
||||
|
||||
private static ArcInspector getRandomArcFilter() {
|
||||
final Random rand = new Random();
|
||||
// final Random rand = new Random();
|
||||
final List<ArcInspector> filters = ArcInspectorFactory.getAllFilters();
|
||||
//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) {
|
||||
|
|
Loading…
Reference in a new issue