Commentaire dans Launch pour tester , TestDijkstra presque termine,DijkstraAlgorithm prise en compte cas origin est la destination
This commit is contained in:
parent
6f81f4d860
commit
4e9989d7ae
4 changed files with 194 additions and 7 deletions
|
@ -115,7 +115,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tableau_label[destination.getId()].getmarque()==false) {
|
if(tableau_label[destination.getId()].getmarque()==false ||destination == origin ) {
|
||||||
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
|
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -0,0 +1,188 @@
|
||||||
|
package org.insa.graphs.algorithm.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
||||||
|
import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Graph;
|
||||||
|
import org.insa.graphs.model.Node;
|
||||||
|
import org.insa.graphs.model.Path;
|
||||||
|
import org.insa.graphs.model.io.BinaryGraphReader;
|
||||||
|
import org.insa.graphs.model.io.GraphReader;
|
||||||
|
public class TestDijkstra {
|
||||||
|
/* Définissez plusieurs scénarios. Chaque scénario est défini par :
|
||||||
|
une carte (tester des cartes routières et non routières)
|
||||||
|
la nature du coût (tester en distance et en temps)
|
||||||
|
une origine et une destination (tester plusieurs valeurs) */
|
||||||
|
|
||||||
|
/* Les scénarios doivent être convaincants et représentatifs des situations
|
||||||
|
pouvant arriver (chemin inexistant, chemin de longueur nulle, trajet court,
|
||||||
|
trajet long et pénible avec des enfants, ...).*/
|
||||||
|
|
||||||
|
/* Sur ces scénarios, vérifier que le chemin construit par votre algo est valide.
|
||||||
|
Vérifiez aussi que le coût du chemin calculé par Dijkstra est bien le même que celui calculé par la classe Path. Depuis la 1A vous savez qu'on ne compare pas deux réels avec ==.
|
||||||
|
Sur les petits scénarios, vérifiez que vous obtenez les mêmes résultats qu'avec Bellman-Ford (que faut-il tester ?)
|
||||||
|
Sur les scénarios plus grands, Bellman-Ford sera inutilisable. Réfléchissez à quelques tests automatiques que vous pouvez tout de même effectuer pour vous rassurer sur le chemin trouvé.
|
||||||
|
Concevez vos tests de manière modulaire : vous les ré-utiliserez pour A-star. */
|
||||||
|
|
||||||
|
/* Tests modulaires cad :Reusable: You can use the same test for Dijkstra, Bellman-Ford, and later A*.
|
||||||
|
|
||||||
|
Isolated: Each test checks one specific thing (e.g., cost matches, or validity of path).
|
||||||
|
|
||||||
|
Automated: No need for manual launching or visual inspection.*/
|
||||||
|
|
||||||
|
// fonction pour recuperer les graphs
|
||||||
|
// visit these directory to see the list of available files on commetud.
|
||||||
|
|
||||||
|
|
||||||
|
Graph graph = null;
|
||||||
|
Path path = null;
|
||||||
|
|
||||||
|
// create a graph reader
|
||||||
|
/* try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||||
|
new BufferedInputStream(new FileInputStream(mapName))))) {
|
||||||
|
|
||||||
|
// TODO: read the graph
|
||||||
|
graph = reader.read();
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: create a path reader
|
||||||
|
// Je suis là et c'est là que je dois faire les changements nécessaires
|
||||||
|
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
|
||||||
|
new BufferedInputStream(new FileInputStream(pathName))))) {
|
||||||
|
|
||||||
|
// TODO: read the path
|
||||||
|
path = pathReader.readPath(graph);
|
||||||
|
}*/
|
||||||
|
// fonction pour recuperer les paths
|
||||||
|
// create a graph reader
|
||||||
|
void graphlecture (Graph graph,String mapName) throws Exception {
|
||||||
|
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||||
|
new BufferedInputStream(new FileInputStream(mapName))))) {
|
||||||
|
|
||||||
|
// TODO: read the graph
|
||||||
|
graph = reader.read();
|
||||||
|
reader.close();
|
||||||
|
}}
|
||||||
|
|
||||||
|
// Scénario 1 : trajet court petite map
|
||||||
|
final String mapName1= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
final String pathName1 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
||||||
|
// Scénario 2 : trajet long petite map
|
||||||
|
final String mapName2= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
Graph graphe2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Scénario 3: trajet court grande map
|
||||||
|
final String mapName3= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/belgium.mapgr";
|
||||||
|
final String pathName3 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_be_173101_302442.path";
|
||||||
|
// Scénario 4: trajet long grande map
|
||||||
|
final String mapName4= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/belgium.mapgr";
|
||||||
|
|
||||||
|
// Scénario 5: Chemin inexistant cas 1: origine et destination dans deux composantes connexes différentes
|
||||||
|
final String mapName5= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/french-polynesia.mapgr";
|
||||||
|
// Scénario 6.1: Chemin inexistant cas 2: origine et destination inaccessibles avec la voiture
|
||||||
|
final String mapName6= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
final String pathName6 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_bikini_motorcar.path";
|
||||||
|
// Scénario 6.2: Meme chemin test pour pieton
|
||||||
|
final String mapName7= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
final String pathName7 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
||||||
|
|
||||||
|
// Scénario 8: Chemin de longueur nulle (origine = destination)
|
||||||
|
final String mapName8= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
|
////Node Origin = 1333; Node Destination =1103;
|
||||||
|
// Scénario 9: Test chemin court par rapport temps
|
||||||
|
final String mapName9 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
|
||||||
|
final String pathName9 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_time.path";
|
||||||
|
// Scénario 10: Test chemin court par rapport distance
|
||||||
|
final String mapName10 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/haute-garonne.mapgr";
|
||||||
|
final String pathName10 ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_aeroport_length.path";
|
||||||
|
/* Tests pour l'ensembles des scénarios*/
|
||||||
|
|
||||||
|
// Vérifier la validité du chemin : utilisation de .isvalid()
|
||||||
|
// fonction verifiant que deux chemins sont les memes
|
||||||
|
public static boolean bonchemin (Path chemintrouve,Path cheminrecherche){
|
||||||
|
// on regarde d'abord si les chemins sont valides
|
||||||
|
if(!(chemintrouve.isValid()) || !(cheminrecherche.isValid()) ){
|
||||||
|
System.out.println(" chemin(s) non valide");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// on verifie si les chemins ont le meme nombre de noeuds
|
||||||
|
if(chemintrouve.size() != cheminrecherche.size()){
|
||||||
|
System.out.println(" chemins de taille différente");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// recuperation liste des arcs
|
||||||
|
List<Arc> arcstrouves = chemintrouve.getArcs();
|
||||||
|
List<Arc> arcsrecherches = cheminrecherche.getArcs();
|
||||||
|
// On verifie si les chemins utilisent les mêmes arcs
|
||||||
|
for (int i=0; i<chemintrouve.getArcs().size();i++){
|
||||||
|
// on recupere les arcs de chaque iteration
|
||||||
|
Arc arctrouve = arcstrouves.get(i);
|
||||||
|
Arc arcrecherche = arcsrecherches.get(i);
|
||||||
|
if(!(arctrouve.getOrigin().equals(arcrecherche.getOrigin())) || !(arctrouve.getDestination().equals(arcrecherche.getDestination()) )){
|
||||||
|
System.out.println("A partir de l'arc "+i + "les chemins sont differents");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Pour petites cartes
|
||||||
|
// Recuperer origine
|
||||||
|
//public static Node getOrigin
|
||||||
|
// Vérifier que le coût en temps est similaire entre Dijkstra et Bellman-Ford
|
||||||
|
public static boolean memetemps (Graph graph,Node Origin,Node Destination,ArcInspector arcInspector){
|
||||||
|
ShortestPathData Data = new ShortestPathData(graph, Origin, Destination, arcInspector);
|
||||||
|
// Recuperation Path de Dijkstra
|
||||||
|
DijkstraAlgorithm Dijkstra = new DijkstraAlgorithm(Data);
|
||||||
|
ShortestPathSolution SolutionDijkstra = Dijkstra.run();
|
||||||
|
Path PathDijkstra =SolutionDijkstra.getPath();
|
||||||
|
// Recuperation Path de BellmanFord
|
||||||
|
BellmanFordAlgorithm BellmanFord = new BellmanFordAlgorithm(Data);
|
||||||
|
ShortestPathSolution SolutionBellmanFord = BellmanFord.run();
|
||||||
|
Path PathBellmanFord =SolutionBellmanFord.getPath();
|
||||||
|
// Verifier si un path existe avant de verifier sa validite pour eviter probs de pointeur
|
||||||
|
if (PathDijkstra == null || PathBellmanFord == null) {
|
||||||
|
System.out.println("Path(s) null(s)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Verification de la validité des Path
|
||||||
|
if(!(PathDijkstra.isValid())|| !(PathBellmanFord.isValid()) ){
|
||||||
|
System.out.println("Path(s) non valide(s)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Les deux doivent avoir trouvé un path
|
||||||
|
// if (SolutionDijkstra.getStatus() != AbstractSolution.Status.OPTIMAL || SolutionBellman.getStatus() != AbstractSolution.Status.OPTIMAL) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
// verification de la similarite en temps avec un certain epsilon
|
||||||
|
double CostDijkstra = PathDijkstra.getMinimumTravelTime();
|
||||||
|
double CostBellmanFord = PathBellmanFord.getMinimumTravelTime();
|
||||||
|
double epsilon = 1e-6;
|
||||||
|
if(Math.abs(CostDijkstra - CostBellmanFord)>epsilon){
|
||||||
|
System.out.println("Dijkstra et BellmanFord on des coûts différents");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Vérifier que le coût en distance est similaire entre Dijkstra et Bellman-Ford
|
||||||
|
|
||||||
|
// Pour grandes cartes
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//graphlecture(graphe2,mapName2);
|
||||||
|
//Node Origin = Graphe2.get(1333);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,10 +46,10 @@ public class Launch {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
// visit these directory to see the list of available files on commetud.
|
// visit these directory to see the list of available files on commetud.
|
||||||
final String mapName =
|
final String mapName ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
||||||
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
|
//final String mapName ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/midi-pyrenees.mapgr";
|
||||||
final String pathName =
|
final String pathName ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
||||||
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
|
//final String pathName ="/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31_insa_tour.path";
|
||||||
|
|
||||||
final Graph graph;
|
final Graph graph;
|
||||||
final Path path;
|
final Path path;
|
||||||
|
|
|
@ -294,8 +294,7 @@ public class Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of arcs in the// System.out.println("aaaaaaaaaaaaa"); //
|
* @return List of arcs in the path.
|
||||||
* System.out.println(arcs); path.
|
|
||||||
*/
|
*/
|
||||||
public List<Arc> getArcs() {
|
public List<Arc> getArcs() {
|
||||||
return Collections.unmodifiableList(arcs);
|
return Collections.unmodifiableList(arcs);
|
||||||
|
|
Loading…
Reference in a new issue