Tests 3 cas de scenarios
This commit is contained in:
parent
2e6b971790
commit
60e195fd03
1 changed files with 180 additions and 19 deletions
|
@ -5,6 +5,7 @@ import java.io.DataInputStream;
|
|||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractSolution;
|
||||
import org.insa.graphs.algorithm.ArcInspector;
|
||||
import org.insa.graphs.algorithm.ArcInspectorFactory;
|
||||
import org.insa.graphs.algorithm.shortestpath.BellmanFordAlgorithm;
|
||||
|
@ -109,10 +110,50 @@ final String mapName8= "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps
|
|||
// Vérifier la validité du chemin : utilisation de .isvalid()
|
||||
// fonction qui extrait le chemin valide
|
||||
|
||||
public static boolean SolutionInfaisableDijkstra (ShortestPathData Data){
|
||||
DijkstraAlgorithm Dijkstra = new DijkstraAlgorithm(Data);
|
||||
ShortestPathSolution SolutionDijkstra = Dijkstra.run();
|
||||
if (SolutionDijkstra.getStatus()!=AbstractSolution.Status.INFEASIBLE){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean SolutionInfaisableBellmanFord (ShortestPathData Data){
|
||||
BellmanFordAlgorithm BellmanFord = new BellmanFordAlgorithm(Data);
|
||||
ShortestPathSolution SolutionBellmanFord= BellmanFord.run();
|
||||
if (SolutionBellmanFord.getStatus()!=AbstractSolution.Status.INFEASIBLE){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean boncheminDijkstra (ShortestPathData Data,Path chemindepart){
|
||||
// on regarde d'abord si les chemins sont valides
|
||||
|
||||
Path chemintrouve = Path_Dijkstra(Data);
|
||||
// Cas 1 : aucun chemin n'existe
|
||||
if (chemintrouve == null && chemindepart == null) {
|
||||
System.out.println("Aucun chemin trouvé (null).");
|
||||
return true; // les deux algos ont échoué à trouver un chemin, cohérent
|
||||
}
|
||||
if (chemintrouve == null || chemindepart == null) {
|
||||
System.out.println("Un seul chemin est null, l'autre non.");
|
||||
return false; // incohérence entre les deux
|
||||
}
|
||||
|
||||
// Cas 2 : chemin vide (origine = destination, coût nul)
|
||||
if (chemintrouve.isEmpty() && chemindepart.isEmpty()) {
|
||||
System.out.println("Chemins vides mais valides (origine = destination).");
|
||||
return true;
|
||||
}
|
||||
if (chemintrouve.isEmpty() || chemindepart.isEmpty()) {
|
||||
System.out.println("Un seul chemin vide, l'autre non.");
|
||||
return false;
|
||||
}
|
||||
if(!(chemintrouve.isEmpty()) && chemindepart.isEmpty() ){
|
||||
System.out.println(" chemin vide");
|
||||
return true;
|
||||
}
|
||||
if(!(chemintrouve.isValid()) || !(chemindepart.isValid()) ){
|
||||
System.out.println(" chemin(s) non valide");
|
||||
return false;
|
||||
|
@ -195,7 +236,7 @@ public static boolean memetemps (ShortestPathData Data){
|
|||
System.out.println("Dijkstra et BellmanFord ont des temps différents de parcours");
|
||||
return false;
|
||||
}
|
||||
System.out.println("Dijkstra et BellmanFord ont les même temps de parcours");
|
||||
System.out.println("Dijkstra et BellmanFord ont les même temps de parcours"+CostDijkstra);
|
||||
return true;
|
||||
}
|
||||
// Vérifier que le coût en distance est similaire entre Dijkstra et Bellman-Ford
|
||||
|
@ -222,11 +263,10 @@ public static boolean memedistance (ShortestPathData Data){
|
|||
System.out.println("Dijkstra et BellmanFord ont des distances différentes de parcours");
|
||||
return false;
|
||||
}
|
||||
System.out.println("Dijkstra et BellmanFord ont les même distances de parcours");
|
||||
System.out.println("Dijkstra et BellmanFord ont les même distances de parcours" + CostDijkstra);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean memepath (ShortestPathData Data){
|
||||
public static boolean memepathtemps (ShortestPathData Data){
|
||||
// Recuperation Path de Dijkstra
|
||||
Path PathDijkstra =Path_Dijkstra(Data);
|
||||
// Recuperation Path de BellmanFord
|
||||
|
@ -260,6 +300,53 @@ public static boolean memepath (ShortestPathData Data){
|
|||
// Recuperation du cout des arcs
|
||||
Double tempsArcDijkstra = ArcsDijkstra.get(i).getMinimumTravelTime();
|
||||
Double tempsArcBellmanFord = ArcsBellmanFord.get(i).getMinimumTravelTime();
|
||||
|
||||
if(OrigineDijkstra.getId()!= OrigineBellmanFord.getId()|| DestinationDijkstra.getId()!= DestinationBellmanFord.getId() ){
|
||||
System.out.println("A partir de l'arc"+i+"les paths ne sont pas les mêmes");
|
||||
return false;
|
||||
}
|
||||
final double EPSILON = 1e-3;
|
||||
if(Math.abs(tempsArcDijkstra - tempsArcBellmanFord )> EPSILON){
|
||||
System.out.println("A partir de l'arc"+i+"les paths n'ont plus la meme taille");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Dijkstra et BellmanFord ont les même paths");
|
||||
return true;
|
||||
}
|
||||
public static boolean memepathdistance (ShortestPathData Data){
|
||||
// Recuperation Path de Dijkstra
|
||||
Path PathDijkstra =Path_Dijkstra(Data);
|
||||
// Recuperation Path de BellmanFord
|
||||
Path PathBellmanFord =Path_BellmanFord(Data);
|
||||
|
||||
// Verifier si un path existe avant de verifier sa validite pour eviter probs de pointeur
|
||||
if (!ExistancePaths(PathDijkstra, PathBellmanFord)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verification de la validité des Path
|
||||
if(!ValiditePaths(PathDijkstra, PathBellmanFord)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// verification de la similarite des paths
|
||||
// comparer l'ensemble des origines et destination des arcs et leurs couts
|
||||
List<Arc> ArcsDijkstra = PathDijkstra.getArcs();
|
||||
List<Arc> ArcsBellmanFord = PathBellmanFord.getArcs();
|
||||
// Verifier si on a la meme taille d'arc
|
||||
if(ArcsDijkstra.size() != ArcsBellmanFord.size()){
|
||||
return false;
|
||||
}
|
||||
// Verifier que les arcs ont même origine et même destination
|
||||
for (int i=0;i<ArcsDijkstra.size();i++){
|
||||
// Recuperation des Origines et Destinations
|
||||
Node OrigineDijkstra = ArcsDijkstra.get(i).getOrigin();
|
||||
Node OrigineBellmanFord = ArcsBellmanFord.get(i).getOrigin();
|
||||
Node DestinationDijkstra = ArcsDijkstra.get(i).getDestination();
|
||||
Node DestinationBellmanFord = ArcsBellmanFord.get(i).getDestination();
|
||||
// Recuperation du cout des arcs
|
||||
float distanceArcDijkstra = ArcsDijkstra.get(i).getLength();
|
||||
float distanceArcBellmanFord = ArcsBellmanFord.get(i).getLength();
|
||||
|
||||
|
@ -267,8 +354,7 @@ public static boolean memepath (ShortestPathData Data){
|
|||
System.out.println("A partir de l'arc"+i+"les paths ne sont pas les mêmes");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tempsArcDijkstra != tempsArcBellmanFord || distanceArcDijkstra!= distanceArcBellmanFord ){
|
||||
if( distanceArcDijkstra!= distanceArcBellmanFord ){
|
||||
System.out.println("A partir de l'arc"+i+"les paths n'ont plus la meme taille");
|
||||
return false;
|
||||
}
|
||||
|
@ -286,29 +372,104 @@ public static boolean memepath (ShortestPathData Data){
|
|||
ArcInspector OnlyCarByLength = filters.get(1);
|
||||
ArcInspector OnlyCarByTime= filters.get(2);
|
||||
ArcInspector OnlyPedestrianByTime = filters.get(3);
|
||||
// petite carte chemin existant pour tous filtres
|
||||
//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";
|
||||
// Recuperation du graph et path de la situation
|
||||
// cas 1 NofilterbyLength : a un path
|
||||
Graph graph = graphlecture(mapName1);
|
||||
Path pathrecupere1 = pathlecture(graph, pathName1);
|
||||
// Recuperation du path realise par Dijkstra
|
||||
ShortestPathData Data1 = new ShortestPathData(graph,pathrecupere1.getOrigin(), pathrecupere1.getDestination(),Nofilterbylength);
|
||||
// verification du bon chemin
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test bonchemin\n ");
|
||||
if(boncheminDijkstra(Data1, pathrecupere1)){
|
||||
System.out.println("L'algorithme Dijkstra donne le bon path");
|
||||
System.out.println("L'algorithme Dijkstra donne le bon path\n ");
|
||||
}
|
||||
else{System.out.println("L'algorithme Dijkstra ne donne pas le bon path");}
|
||||
|
||||
else{System.out.println("L'algorithme Dijkstra ne donne pas le bon path\n");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
// Comparaison avec Bellman Ford
|
||||
// Comparaison de cout en distance
|
||||
//if(memedistance(Data1)){
|
||||
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme distance Bellman-Ford et Dijkstra\n ");
|
||||
if(memedistance(Data1)){
|
||||
System.out.println("Dijkstra et Bellman Ford donnent le même coût\n ");
|
||||
}
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas le même\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme temps Bellman-Ford et Dijkstra\n ");
|
||||
if(memetemps(Data1)){
|
||||
System.out.println("Dijkstra et Bellman Ford donnent le même temps\n ");
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas le même temps\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
// comparaison des paths
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme distance Bellman-Ford et Dijkstra\n ");
|
||||
if(memepathdistance(Data1)){
|
||||
System.out.println("Dijkstra et Bellman Ford ont le meme path\n ");
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas le même path\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
// cas 2 Filter OnlyCarbylength : pas de path
|
||||
// Recuperation du path realise par Dijkstra
|
||||
ShortestPathData Data2 = new ShortestPathData(graph,pathrecupere1.getOrigin(), pathrecupere1.getDestination(),OnlyCarByLength);
|
||||
// verification du fait qu'on n'a pas de chemin
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test Solution Infaisable\n ");
|
||||
if(SolutionInfaisableDijkstra(Data2)){
|
||||
System.out.println("L'algorithme Dijkstra donne le bon path : infaisable\n ");
|
||||
}
|
||||
else{System.out.println("L'algorithme Dijkstra ne donne pas le bon path\n");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
// Comparaison avec Bellman Ford : Voir si meme Bellman Ford ne donne rien dans ce cas
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme distance Bellman-Ford et Dijkstra\n ");
|
||||
if(SolutionInfaisableBellmanFord(Data2)){
|
||||
System.out.println("BellmanFord donne un path infaisable \n ");
|
||||
}
|
||||
else{System.out.println("BellmanFord donne un path faisable\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
|
||||
|
||||
// cas 3 Filter OnlyCarbytime: pas de path
|
||||
// Recuperation du path realise par Dijkstra
|
||||
ShortestPathData Data3 = new ShortestPathData(graph,pathrecupere1.getOrigin(), pathrecupere1.getDestination(),OnlyCarByTime);
|
||||
// Comparaison avec Bellman Ford
|
||||
// Comparaison de cout en distance
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme distance Bellman-Ford et Dijkstra\n ");
|
||||
if(memedistance(Data3)){
|
||||
System.out.println("Dijkstra et Bellman Ford donnent la meme distance\n ");
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas la meme distance\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme temps Bellman-Ford et Dijkstra\n ");
|
||||
if(memetemps(Data3)){
|
||||
System.out.println("Dijkstra et Bellman Ford donnent le même temps\n ");
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas le même temps\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
|
||||
// comparaison des paths
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
System.out.println("Test meme path Bellman-Ford et Dijkstra\n ");
|
||||
if(memepathdistance(Data3)){
|
||||
System.out.println("Dijkstra et Bellman Ford ont le meme path\n ");
|
||||
}
|
||||
else{System.out.println("Dijkstra et Bellman Ford ne donnent pas le même path\n ");}
|
||||
System.out.println("---------------------------------------------------\n ");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue