feat(time-trial): output csv data

This commit is contained in:
Paul Alnet 2024-05-21 18:17:47 +02:00
parent 017d65f57c
commit 7545364b39

View file

@ -15,21 +15,35 @@ import org.insa.graphs.model.io.BinaryGraphReader;
import org.insa.graphs.model.io.GraphReader;
public class RunTimeTrial {
final static int TEST_COUNT = 10;
final static int TEST_COUNT = 100;
public static void main(String[] args) throws Exception {
final Graph graph = readGraph("./Maps/france.mapgr");
final Graph graph = readGraph("./Maps/midi-pyrenees.mapgr");
long totalDijkstraTime = 0;
long totalAStarTime = 0;
long totalBellmanTime = 0;
System.err.println("N D A B");
for (int i = 0; i < TEST_COUNT; i++) {
System.out.println("Running time trial " + i + "/" + TEST_COUNT);
//System.out.println("Running time trial " + i + "/" + TEST_COUNT);
final ShortestPathData data = getRandomShortestPathData(graph);
totalDijkstraTime += new DijkstraAlgorithm(data).run().getSolvingTime().toMillis();
totalAStarTime += new AStarAlgorithm(data).run().getSolvingTime().toMillis();
//totalBellmanTime += new BellmanFordAlgorithm(data).run().getSolvingTime().toMillis();
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");
@ -47,7 +61,8 @@ public class RunTimeTrial {
private static ArcInspector getRandomArcFilter() {
final Random rand = new Random();
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);
}
private static ShortestPathData getRandomShortestPathData(Graph graph) {