1
0
Fork 0

Finished ShortestPathTest for Bellman and Dijkstra

This commit is contained in:
Yanis Mahé 2026-05-12 15:45:53 +02:00
parent 3df94a9cec
commit 5de1caec47

View file

@ -31,12 +31,14 @@ public class ShortestPathTest {
final static String midiPyreneesFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/midi-pyrenees.mapgr";
final static String hauteGaronneFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
final static String insaFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
final static String belgiqueFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Maps/belgium.mapgr";
final static String insaBikiniCanalPathFile = "/mnt/commetud/3emeAnneeMIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_bikini_canal.path";
static Graph midiPyrenees;
static Graph hauteGaronne;
static Graph insa;
static Graph belgique;
static Path insaBikiniCanal;
@ -59,6 +61,10 @@ public class ShortestPathTest {
new BufferedInputStream(new FileInputStream(insaFile))))) {
insa = reader.read();
}
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
new BufferedInputStream(new FileInputStream(belgiqueFile))))) {
belgique = reader.read();
}
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
new BufferedInputStream(new FileInputStream(insaBikiniCanalPathFile))))) {
@ -73,7 +79,7 @@ public class ShortestPathTest {
@Test
public void testCheminInsaBikiniCanal() {
public void testCheminInsaBikiniCanal() { // En comparant avec un fichier path
ShortestPathData insaBikiniCanalPathData = new ShortestPathData(hauteGaronne, insaBikiniCanal.getOrigin(), insaBikiniCanal.getDestination(), noFilterByLengthArcInspector);
// System.out.println("" + insaBikiniCanal.getOrigin().getId() +" "+ insaBikiniCanal.getDestination().getId());
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(insaBikiniCanalPathData);
@ -82,6 +88,9 @@ public class ShortestPathTest {
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
ShortestPathSolution solutionDijkstra = dijkstra.run();
assertEquals(Status.OPTIMAL, solutionBellmanFord.getStatus());
assertEquals(Status.OPTIMAL, solutionDijkstra.getStatus());
assertEquals(insaBikiniCanal.getLength(), solutionBellmanFord.getPath().getLength(),1.0);
assertEquals(insaBikiniCanal.getLength(), solutionDijkstra.getPath().getLength(), 1.0);
@ -102,4 +111,33 @@ public class ShortestPathTest {
assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus());
}
@Test
public void testCheminLongueurNulle() {
ShortestPathData cheminInexistant = new ShortestPathData(insa, insa.get(940), insa.get(940), noFilterByLengthArcInspector);
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
ShortestPathSolution solutionDijkstra = dijkstra.run();
assertEquals(Status.INFEASIBLE, solutionBellmanFord.getStatus());
assertEquals(Status.INFEASIBLE, solutionDijkstra.getStatus());
assertNull(solutionBellmanFord.getPath());
assertNull(solutionDijkstra.getPath());
}
@Test
public void testCheminLong() { // En comparant les deux algos
ShortestPathData cheminInexistant = new ShortestPathData(belgique, belgique.get(956754), belgique.get(842938), noFilterByLengthArcInspector);
ShortestPathAlgorithm bellmanFord = new BellmanFordAlgorithm(cheminInexistant);
ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(cheminInexistant);
ShortestPathSolution solutionBellmanFord = bellmanFord.run();
ShortestPathSolution solutionDijkstra = dijkstra.run();
assertEquals(solutionBellmanFord.getStatus(), solutionDijkstra.getStatus());
assertEquals(solutionBellmanFord.getPath().getLength(), solutionDijkstra.getPath().getLength(), 1.0);
assertEquals(solutionBellmanFord.getPath().getTravelTime(120), solutionDijkstra.getPath().getTravelTime(120), 1.0);
}
}