diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java index 2c5f944..db622ca 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java @@ -4,8 +4,10 @@ package org.insa.graphs.algorithm.shortestpath; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.ArrayList; +import org.insa.graphs.algorithm.AbstractInputData.Mode; import org.insa.graphs.algorithm.AbstractSolution.Status; import org.insa.graphs.algorithm.utils.BinaryHeap; import org.insa.graphs.algorithm.utils.ElementNotFoundException; @@ -34,42 +36,65 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { } tabLabel[data.getOrigin().getId()].setCout(0); tas.insert(tabLabel[data.getOrigin().getId()]); + this.notifyOriginProcessed(data.getOrigin()); //int nbMarque=0; + int iterations=0; while(!tabLabel[data.getDestination().getId()].isMarque()) { - Node X=tas.findMin().getSommetCourant(); + iterations++; + Node X; + try + { + X=tas.findMin().getSommetCourant(); + } + catch(org.insa.graphs.algorithm.utils.EmptyPriorityQueueException e) + { + System.out.println("Tas vide \n"); + break; + } tabLabel[X.getId()].setMarque(true); + this.notifyNodeMarked(X); + System.out.println("Coût: "+tas.findMin().getCout()+"\n"); //nbMarque++; try { tas.remove(tabLabel[X.getId()]); } catch(ElementNotFoundException e) {System.out.println("The element was not found in the binary heap \n");} + int nbSuccesseurs=0; for(Arc a: X.getSuccessors()) { + nbSuccesseurs++; Node Y=a.getDestination(); if(!tabLabel[Y.getId()].isMarque()) { //double cout_avant=tabLabel[Y.getId()].getCout(); - if(((tabLabel[X.getId()].getCout()+a.getLength()) arcs = new ArrayList<>(); Arc arc = tabLabel[data.getDestination().getId()].getPere(); while (arc != null) { arcs.add(arc); arc = tabLabel[arc.getOrigin().getId()].getPere(); } - + System.out.println("Nombre d'arcs: "+arcs.size() + "\n"); + System.out.println("Nombre d'itérations: "+iterations + "\n"); // Reverse the path... Collections.reverse(arcs); - + + //Vérification grâce à Path.createShortestPathFromNodes + Path p= new Path(graph,arcs); + //List noeuds=new ArrayList(); + float cout_total=0; + for(Arc a: arcs) + { + cout_total += a.getLength(); + } + if(p.getLength()==cout_total) + { + System.out.println("La longueur du plus court chemin est la même que celle calculée grâce à Dijkstra \n"); + } + else + { + + System.out.println("ERREUR: La longueur du plus court chemin n'est la même que celle calculée grâce à Dijkstra \n"); + System.out.println("Cout Dijktra="+cout_total); + System.out.println("Cout Dijktra="+p.getLength()); + } + /*noeuds.add(data.getDestination()); + + if(data.getMode()==Mode.LENGTH) + { + Path shortestpath=Path.createShortestPathFromNodes(graph, noeuds); + + if(shortestpath.getLength()==p.getLength()) + { + System.out.println("La longueur du plus court chemin est la même que celle calculée grâce à Dijkstra \n"); + } + else + { + System.out.println("ERREUR: La longueur du plus court chemin n'est la même que celle calculée grâce à Dijkstra \n"); + } + } + + else + { + Path fastestpath=Path.createFastestPathFromNodes(graph, noeuds); + + if(fastestpath.getMinimumTravelTime()==p.getMinimumTravelTime()) + { + System.out.println("La longueur du plus court chemin est la même que celle calculée grâce à Dijkstra \n"); + } + else + { + System.out.println("ERREUR: La longueur du plus court chemin n'est la même que celle calculée grâce à Dijkstra \n"); + } + }*/ + + //Vérification de la validation du path + if(p.isValid()) + { + System.out.println("Félicitation votre path est valide \n"); + } + else + { + System.out.println("Erreur! votre path est invalide \n"); + } // Create the final solution. solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs)); } diff --git a/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.class b/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.class index 992c3a6..48333f3 100644 Binary files a/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.class and b/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.class differ diff --git a/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/Label.class b/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/Label.class index 3940f69..9815170 100644 Binary files a/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/Label.class and b/be-graphes-algos/target/classes/org/insa/graphs/algorithm/shortestpath/Label.class differ