refactor(time-trial): move test run to own function

This commit is contained in:
Paul Alnet 2024-05-25 21:58:06 +02:00
parent 4c71453889
commit db889e56e4

View file

@ -15,28 +15,36 @@ import org.insa.graphs.model.io.BinaryGraphReader;
import org.insa.graphs.model.io.GraphReader;
public class RunTimeTrial {
final static int TEST_COUNT_PER_MAP = 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);
}
System.err.println("N P D A B");
public static void runTest(String mapName, boolean runBellman) throws IOException {
final Graph graph = readGraph(mapName);
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();
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() + " "
//+ bellmanSolution.getSolvingTime().toMillis() + " "
graph.size() + ","
+ pathSize + ","
+ dijkstraSolution.getSolvingTime().toMillis() + ","
+ aStarSolution.getSolvingTime().toMillis() + ","
+ (runBellman ? bellmanSolution.getSolvingTime().toMillis() : "")
);
}
}
@ -49,10 +57,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) {