Added paths + syntax for tests
This commit is contained in:
parent
1e3b3293a4
commit
ed48a95832
9 changed files with 70 additions and 30 deletions
BIN
Paths/custom_paths/bikini_insa_midi_pyrennees_all_roads.path
Normal file
BIN
Paths/custom_paths/bikini_insa_midi_pyrennees_all_roads.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/chemin_canal_insa.path
Normal file
BIN
Paths/custom_paths/chemin_canal_insa.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/long_path_carre.path
Normal file
BIN
Paths/custom_paths/long_path_carre.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/long_path_insa.path
Normal file
BIN
Paths/custom_paths/long_path_insa.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/long_path_tls.path
Normal file
BIN
Paths/custom_paths/long_path_tls.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/short_path_carre.path
Normal file
BIN
Paths/custom_paths/short_path_carre.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/short_path_insa.path
Normal file
BIN
Paths/custom_paths/short_path_insa.path
Normal file
Binary file not shown.
BIN
Paths/custom_paths/short_path_tls.path
Normal file
BIN
Paths/custom_paths/short_path_tls.path
Normal file
Binary file not shown.
|
@ -7,6 +7,7 @@ import java.io.DataInputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import org.insa.graphs.algorithm.ArcInspector;
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||||
|
@ -17,51 +18,87 @@ import org.insa.graphs.model.io.BinaryPathReader;
|
||||||
import org.insa.graphs.model.io.GraphReader;
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
import org.insa.graphs.model.io.PathReader;
|
import org.insa.graphs.model.io.PathReader;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Assume;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import org.junit.runners.Parameterized.Parameter;
|
||||||
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DijkstraAlgorithmTest {
|
public class DijkstraAlgorithmTest {
|
||||||
|
|
||||||
// TODO finish this
|
// TODO finish this
|
||||||
public static GraphReader reader;
|
public static GraphReader reader;
|
||||||
public static Graph graph;
|
public static ArrayList<Graph> graph = new ArrayList<Graph>();
|
||||||
public static PathReader pathReader;
|
public static PathReader pathReader;
|
||||||
public static Path path;
|
public static ArrayList<Path> path = new ArrayList<Path>();
|
||||||
|
|
||||||
|
@Parameter
|
||||||
|
static ArrayList<String> Maps = new ArrayList<String>(Arrays.asList("../Maps/carre.mapgr",
|
||||||
|
"../Maps/insa.mapgr","../Maps/toulouse.mapgr"));
|
||||||
|
|
||||||
|
//TODO: chemins map carree à creer
|
||||||
|
// chemins maps insa à remettre
|
||||||
|
// chemins map toulouse à créer
|
||||||
|
// Chemin inexistant: carte INSA : nodes 224 --> 814
|
||||||
|
|
||||||
|
// test optimalité : long chemin: belgique espagne
|
||||||
|
|
||||||
|
static ArrayList<String> Paths_CARREE = new ArrayList<String>(Arrays.asList(""));
|
||||||
|
static ArrayList<String> Paths_TLS = new ArrayList<String>(Arrays.asList(""));
|
||||||
|
static ArrayList<String> Paths_INSA = new ArrayList<String>(Arrays.asList( "../Paths/path_fr31insa_rangueil_r2.path",
|
||||||
|
"../Paths/path_fr31insa_rangueil_insa.path"));
|
||||||
|
|
||||||
|
static ArrayList[] Paths = {Paths_CARREE,Paths_TLS,Paths_TLS};
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
|
||||||
// Visit these directory to see the list of available files on Commetud.
|
// Visit these directory to see the list of available files on Commetud.
|
||||||
// When running with VSC, paths are relative to the BE_Graphes directory.
|
// When running with VSC, paths are relative to the BE_Graphes directory.
|
||||||
final String mapName = "../Maps/insa.mapgr";
|
ArrayList<String> actual_path_list = new ArrayList<String>();
|
||||||
|
for (int j = 0 ; j < Maps.size() ; j++) {
|
||||||
|
actual_path_list = Paths[j];
|
||||||
|
for (int i = 0 ; i < Paths_TLS.size() ; i ++) {
|
||||||
|
final String mapName = Maps.get(j);
|
||||||
|
final String pathName = actual_path_list.get(i);
|
||||||
|
// System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
||||||
|
// Create a graph reader.
|
||||||
|
System.out.println(pathName);
|
||||||
|
System.out.println(mapName);
|
||||||
|
|
||||||
final String pathName = "../Paths/path_fr31insa_rangueil_r2.path";
|
|
||||||
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
|
||||||
// Create a graph reader.
|
|
||||||
try {
|
|
||||||
final GraphReader reader = new BinaryGraphReader(
|
|
||||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
|
||||||
|
|
||||||
// Read the graph. X
|
try {
|
||||||
graph = reader.read();
|
final GraphReader reader = new BinaryGraphReader(
|
||||||
// free resources
|
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
||||||
reader.close();
|
|
||||||
|
|
||||||
// Create a PathReader.
|
// Read the graph. X
|
||||||
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
graph.add(reader.read());
|
||||||
|
// free resources
|
||||||
|
reader.close();
|
||||||
|
|
||||||
// Read the path.
|
// Create a PathReader.
|
||||||
path = pathReader.readPath(graph);
|
final PathReader pathReader = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathName))));
|
||||||
|
|
||||||
// free resources
|
System.out.println(graph.get(i));
|
||||||
pathReader.close();
|
// Read the path.
|
||||||
}
|
path.add(pathReader.readPath(graph.get(i)));
|
||||||
catch (FileNotFoundException e) {
|
|
||||||
System.err.println("File not found: " + e.getMessage());
|
// free resources
|
||||||
fail("File not found: " + e.getMessage());
|
pathReader.close();
|
||||||
}
|
}
|
||||||
catch (IOException e ) {
|
catch (FileNotFoundException e) {
|
||||||
System.err.println("Error reading file: " + e.getMessage());
|
System.err.println("File not found: " + e.getMessage());
|
||||||
fail("Error reading file: " + e.getMessage());
|
fail("File not found: " + e.getMessage());
|
||||||
|
}
|
||||||
|
catch (IOException e ) {
|
||||||
|
System.err.println("Error reading file: " + e.getMessage());
|
||||||
|
fail("Error reading file: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +110,9 @@ public class DijkstraAlgorithmTest {
|
||||||
// Chemin court => Bellman OK et vérifié. On compare les résultats obtenus par les 2 algos
|
// Chemin court => Bellman OK et vérifié. On compare les résultats obtenus par les 2 algos
|
||||||
public void testToulouseCourtChemin() {
|
public void testToulouseCourtChemin() {
|
||||||
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
|
||||||
ShortestPathData data = new ShortestPathData(this.graph, this.path.getOrigin(), this.path.getDestination(), arcInspector);
|
Graph myGraph = graph.get(0);
|
||||||
|
Path myPath = path.get(0);
|
||||||
|
ShortestPathData data = new ShortestPathData(myGraph, myPath.getOrigin(), myPath.getDestination(), arcInspector);
|
||||||
|
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
@ -85,9 +124,10 @@ public class DijkstraAlgorithmTest {
|
||||||
|
|
||||||
// Long chemin => Bellman trop long, on compare dijkstra au chemin récupéré directement
|
// Long chemin => Bellman trop long, on compare dijkstra au chemin récupéré directement
|
||||||
public void testToulouseLongChemin() {
|
public void testToulouseLongChemin() {
|
||||||
init();
|
Graph myGraph = graph.get(0);
|
||||||
|
Path myPath = path.get(0);
|
||||||
ArcInspector arcInspector;
|
ArcInspector arcInspector;
|
||||||
ShortestPathData data = new ShortestPathData(this.graph, this.path.getOrigin(), this.path.getDestination(), null);
|
ShortestPathData data = new ShortestPathData(myGraph, myPath.getOrigin(), myPath.getDestination(), null);
|
||||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||||
ShortestPathSolution dijk_path = dijkstra.doRun();
|
ShortestPathSolution dijk_path = dijkstra.doRun();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue