Utilisation de inspector dans Dijkstra et getter d'inspector dans ShortestPathData

This commit is contained in:
knzrd 2025-05-24 16:51:42 +02:00
parent 58317db92a
commit dc63c1178f
2 changed files with 19 additions and 2 deletions

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.insa.graphs.algorithm.AbstractSolution; import org.insa.graphs.algorithm.AbstractSolution;
import org.insa.graphs.algorithm.ArcInspector;
import org.insa.graphs.algorithm.ArcInspectorFactory;
import org.insa.graphs.algorithm.utils.BinaryHeap; import org.insa.graphs.algorithm.utils.BinaryHeap;
import org.insa.graphs.algorithm.utils.ElementNotFoundException; import org.insa.graphs.algorithm.utils.ElementNotFoundException;
import org.insa.graphs.model.Arc; import org.insa.graphs.model.Arc;
@ -24,12 +26,17 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// retrieve data from the input problem (getInputData() is inherited from the // retrieve data from the input problem (getInputData() is inherited from the
// parent class ShortestPathAlgorithm) // parent class ShortestPathAlgorithm)
final ShortestPathData data = getInputData(); final ShortestPathData data = getInputData();
// on crée un inspector qui nous permettra de savoir si on peut ou pas utiliser un arc
ArcInspector inspector = data.getArcInspector();
// on change l'inspector au mode qui nous intéresse soit ici voiture ( qui est a la deuxieme case du tableau)
//inspector = ArcInspectorFactory.getAllFilters().get(1);
final Graph graph = data.getGraph(); final Graph graph = data.getGraph();
final int nbNodes = graph.size(); final int nbNodes = graph.size();
final Node destination = data.getDestination(); final Node destination = data.getDestination();
final Node origin = data.getOrigin(); final Node origin = data.getOrigin();
// affichage de l'inspector utilisé
System.out.println("Inspector utilisé est : " + inspector.toString());
// variable that will contain the solution of the shortest path problem // variable that will contain the solution of the shortest path problem
ShortestPathSolution solution = null; ShortestPathSolution solution = null;
@ -66,6 +73,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// pour l'ensemble des arts existants à partir du nodecourant // pour l'ensemble des arts existants à partir du nodecourant
for (Arc arcscourants : labelcourant.getsommetcourant().getSuccessors()){ for (Arc arcscourants : labelcourant.getsommetcourant().getSuccessors()){
// Utilisation condition pour savoir si un arc peut être utilisé ou pas en fonction
// du mode de transport (piéton ou voiture )
if(inspector.isAllowed(arcscourants)){
Node successeur = arcscourants.getDestination(); Node successeur = arcscourants.getDestination();
// si le successeur n'est pas marqué on vérifie son coût courant // si le successeur n'est pas marqué on vérifie son coût courant
if(!(tableau_label[successeur.getId()].getmarque())) { if(!(tableau_label[successeur.getId()].getmarque())) {
@ -92,6 +102,8 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
} }
} }
} }
}
} }

View file

@ -40,6 +40,11 @@ public class ShortestPathData extends AbstractInputData {
return destination; return destination;
} }
// Ajout : getter pour l'arc Inspector
public ArcInspector getArcInspector(){
return this.arcInspector;
}
@Override @Override
public String toString() { public String toString() {
return "Shortest-path from #" + origin.getId() + " to #" + destination.getId() return "Shortest-path from #" + origin.getId() + " to #" + destination.getId()