test pour dijkstra
This commit is contained in:
parent
efeba4104c
commit
2b4130887c
1 changed files with 67 additions and 7 deletions
|
@ -1,12 +1,72 @@
|
|||
package org.insa.graphes.model;
|
||||
package org.insa.graphs.gui.simple;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import java.io.*;
|
||||
import org.insa.graphs.model.*;
|
||||
import org.insa.graphs.model.io.*;
|
||||
import org.insa.graphs.algorithm.shortestpath.*;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public class DijkstraTest {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// === Chemins vers les fichiers de test ===
|
||||
final String mapPath = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||
final String pathPath = "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
||||
|
||||
// === Chargement du graphe ===
|
||||
Graph graph;
|
||||
try (GraphReader reader = new BinaryGraphReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(mapPath))))) {
|
||||
graph = reader.read();
|
||||
}
|
||||
|
||||
// === Chargement du chemin de référence ===
|
||||
Path referencePath;
|
||||
try (PathReader pathReader = new BinaryPathReader(
|
||||
new DataInputStream(new BufferedInputStream(new FileInputStream(pathPath))))) {
|
||||
referencePath = pathReader.readPath(graph);
|
||||
}
|
||||
|
||||
// === données pour Dijkstra ===
|
||||
Node origin = referencePath.getOrigin();
|
||||
Node destination = referencePath.getDestination();
|
||||
|
||||
ShortestPathData data = new ShortestPathData(graph, origin, destination, ArcInspectorFactory.getAllFilters().get(0));
|
||||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
|
||||
// === Exécution de l'algorithme ===
|
||||
ShortestPathSolution solution = dijkstra.run();
|
||||
|
||||
|
||||
// === Affichage des résultats ===
|
||||
if (solution.getStatus() == Status.OPTIMAL) {
|
||||
System.out.println("Dijkstra: Chemin trouvé !");
|
||||
System.out.println("Longueur: " + solution.getPath().getLength());
|
||||
System.out.println("Temps estimé (sec): " + solution.getPath().getMinimumTravelTime());
|
||||
} else {
|
||||
System.out.println("Dijkstra: Pas de chemin trouvé.");
|
||||
}
|
||||
|
||||
// === Comparaison avec Bellman-Ford ca peut etre ameliore ===
|
||||
BellmanFordAlgorithm bellman = new BellmanFordAlgorithm(data);
|
||||
ShortestPathSolution bellmanSolution = bellman.run();
|
||||
|
||||
if (bellmanSolution.getStatus() == Status.OPTIMAL) {
|
||||
System.out.println("Bellman-Ford: Chemin trouvé !");
|
||||
System.out.println("Longueur: " + bellmanSolution.getPath().getLength());
|
||||
}
|
||||
|
||||
// === Comparaison en distance et vitesse ===
|
||||
if (solution.getPath() != null && bellmanSolution.getPath() != null) {
|
||||
if (Math.abs(solution.getPath().getLength() - bellmanSolution.getPath().getLength()) < 0.001) {
|
||||
System.out.println("Les deux algorithmes donnent la même longueur.");
|
||||
} else {
|
||||
System.out.println("Les longueurs sont différentes.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue