test dijkstra basique
This commit is contained in:
parent
018d321be4
commit
23fc5a8475
3 changed files with 62 additions and 5 deletions
|
@ -0,0 +1,58 @@
|
||||||
|
package org.insa.graphs.algorithm.utils;
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||||
|
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;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class DijkstraTest {
|
||||||
|
|
||||||
|
private static String mapName;
|
||||||
|
private static GraphReader reader;
|
||||||
|
private static Graph graph;
|
||||||
|
private static Node origin;
|
||||||
|
private static Node destination;
|
||||||
|
private static DijkstraAlgorithm dijkstra;
|
||||||
|
private static BellmanFordAlgorithm bellman;
|
||||||
|
private static ShortestPathSolution solDijkstra;
|
||||||
|
private static ShortestPathSolution solBellman;
|
||||||
|
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void initAll() throws IOException{
|
||||||
|
|
||||||
|
mapName = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
// Create a graph reader.
|
||||||
|
reader = new BinaryGraphReader(
|
||||||
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||||
|
|
||||||
|
// Read the graph.
|
||||||
|
graph = reader.read();
|
||||||
|
//final int numNodes = graph.size();
|
||||||
|
origin = graph.get(0);
|
||||||
|
destination = graph.get(6);
|
||||||
|
dijkstra = new DijkstraAlgorithm(new ShortestPathData(graph,origin,destination,ArcInspectorFactory.getAllFilters().get(0)));
|
||||||
|
bellman = new BellmanFordAlgorithm(new ShortestPathData(graph,origin,destination,ArcInspectorFactory.getAllFilters().get(0)));
|
||||||
|
solDijkstra = dijkstra.run();
|
||||||
|
solBellman = bellman.run();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDijkstra(){
|
||||||
|
assertEquals(solDijkstra.getPath().getLength(),solBellman.getPath().getLength(),0.00001);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -253,7 +253,7 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @return true if the path is valid, false otherwise.
|
* @return true if the path is valid, false otherwise.
|
||||||
*
|
*
|
||||||
* @deprecated Need to be implemented.
|
*
|
||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
@ -282,7 +282,7 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @return Total length of the path (in meters).
|
* @return Total length of the path (in meters).
|
||||||
*
|
*
|
||||||
* @deprecated Need to be implemented.
|
*
|
||||||
*/
|
*/
|
||||||
public float getLength() {
|
public float getLength() {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
@ -301,7 +301,7 @@ public class Path {
|
||||||
* @return Time (in seconds) required to travel this path at the given speed (in
|
* @return Time (in seconds) required to travel this path at the given speed (in
|
||||||
* kilometers-per-hour).
|
* kilometers-per-hour).
|
||||||
*
|
*
|
||||||
* @deprecated Need to be implemented.
|
*
|
||||||
*/
|
*/
|
||||||
public double getTravelTime(double speed) {
|
public double getTravelTime(double speed) {
|
||||||
float res = 0;
|
float res = 0;
|
||||||
|
@ -317,7 +317,7 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @return Minimum travel time to travel this path (in seconds).
|
* @return Minimum travel time to travel this path (in seconds).
|
||||||
*
|
*
|
||||||
* @deprecated Need to be implemented.
|
*
|
||||||
*/
|
*/
|
||||||
public double getMinimumTravelTime() {
|
public double getMinimumTravelTime() {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
|
@ -7,7 +7,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.insa.graphs.model.Arc;
|
import org.insa.graphs.model.Arc;
|
||||||
import org.insa.graphs.model.Graph;
|
import org.insa.graphs.model.Graph;
|
||||||
import org.insa.graphs.model.Node;
|
import org.insa.graphs.model.Node;
|
||||||
|
|
Loading…
Reference in a new issue