Compare commits

..

No commits in common. "017d65f57c8ae4597f846fd2e79902af3648230e" and "d7c938cc76f3aa0f90f2cb48878219e8a6b23aa8" have entirely different histories.

3 changed files with 0 additions and 83 deletions

7
.vscode/launch.json vendored
View file

@ -30,13 +30,6 @@
"request": "launch",
"mainClass": "org.insa.graphs.gui.simple.Launch",
"projectName": "be-graphes-gui"
},
{
"type": "java",
"name": "RunTimeTrial",
"request": "launch",
"mainClass": "org.insa.graphs.algorithm.shortestpath.RunTimeTrial",
"projectName": "be-graphes-gui"
}
]
}

View file

@ -1,75 +0,0 @@
package org.insa.graphs.algorithm.shortestpath;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import org.insa.graphs.algorithm.ArcInspector;
import org.insa.graphs.algorithm.ArcInspectorFactory;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.io.BinaryGraphReader;
import org.insa.graphs.model.io.GraphReader;
public class RunTimeTrial {
final static int TEST_COUNT = 10;
public static void main(String[] args) throws Exception {
final Graph graph = readGraph("./Maps/france.mapgr");
long totalDijkstraTime = 0;
long totalAStarTime = 0;
long totalBellmanTime = 0;
for (int i = 0; i < TEST_COUNT; i++) {
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();
}
System.out.println("Dijkstra took " + totalDijkstraTime + " ms");
System.out.println("A* took " + totalAStarTime + " ms");
System.out.println("Bellman took " + totalBellmanTime + " ms");
}
private static Node getRandomNode(Graph graph) {
final Random rand = new Random();
final int graph_size = graph.getNodes().size();
return graph.get(Math.abs(rand.nextInt()) % graph_size);
}
private static ArcInspector getRandomArcFilter() {
final Random rand = new Random();
final List<ArcInspector> filters = ArcInspectorFactory.getAllFilters();
return filters.get(Math.abs(rand.nextInt()) % filters.size());
}
private static ShortestPathData getRandomShortestPathData(Graph graph) {
final Node origin = getRandomNode(graph);
final Node destination = getRandomNode(graph);
final ArcInspector filter = getRandomArcFilter();
return new ShortestPathData(graph, origin, destination, filter);
}
private static Graph readGraph(String mapName) throws IOException {
// Visit these directory to see the list of available files on Commetud.
// When running with VSC, paths are relative to the BE_Graphes directory.
// Create a graph reader.
final GraphReader reader = new BinaryGraphReader(
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
// Read the graph. X
final Graph graph = reader.read();
// Close resources
reader.close();
return graph;
}
}

View file

@ -78,7 +78,6 @@ public abstract class ShortestPathAlgorithmTest {
/*
* Verifies that path is valid and matches the one found by the Bellman algo
* Otherwise the algo in not optimal.
*/
private void assertBellmanHasSameResult(Graph graph, Node origin, Node destination, ArcInspector arcFilter) {
final ShortestPathData data = new ShortestPathData(graph, origin, destination, arcFilter);