refactor(time-trial): move test run to own function
This commit is contained in:
parent
4c71453889
commit
db889e56e4
1 changed files with 21 additions and 13 deletions
|
@ -15,28 +15,36 @@ 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_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 {
|
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++) {
|
for (int i = 0; i < TEST_COUNT_PER_MAP; i++) {
|
||||||
final ShortestPathData data = getRandomShortestPathData(graph);
|
final ShortestPathData data = getRandomShortestPathData(graph);
|
||||||
|
|
||||||
ShortestPathSolution dijkstraSolution = new DijkstraAlgorithm(data).run();
|
final ShortestPathSolution dijkstraSolution = new DijkstraAlgorithm(data).run();
|
||||||
ShortestPathSolution aStarSolution = new AStarAlgorithm(data).run();
|
final ShortestPathSolution aStarSolution = new AStarAlgorithm(data).run();
|
||||||
//ShortestPathSolution bellmanSolution = new BellmanFordAlgorithm(data).run();
|
final ShortestPathSolution bellmanSolution = runBellman ? new BellmanFordAlgorithm(data).run() : null;
|
||||||
|
|
||||||
final int pathSize = dijkstraSolution.getPath() == null ? -1 : dijkstraSolution.getPath().getArcs().size();
|
final int pathSize = dijkstraSolution.getPath() == null ? -1 : dijkstraSolution.getPath().getArcs().size();
|
||||||
|
|
||||||
System.out.println(
|
System.out.println(
|
||||||
graph.size() + " "
|
graph.size() + ","
|
||||||
+ pathSize + " "
|
+ pathSize + ","
|
||||||
+ dijkstraSolution.getSolvingTime().toMillis() + " "
|
+ dijkstraSolution.getSolvingTime().toMillis() + ","
|
||||||
+ aStarSolution.getSolvingTime().toMillis() + " "
|
+ aStarSolution.getSolvingTime().toMillis() + ","
|
||||||
//+ bellmanSolution.getSolvingTime().toMillis() + " "
|
+ (runBellman ? bellmanSolution.getSolvingTime().toMillis() : "")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,10 +57,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