diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/MyArcInspector.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/MyArcInspector.java index d656bd3..fcc624c 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/MyArcInspector.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/MyArcInspector.java @@ -21,7 +21,13 @@ public class MyArcInspector implements ArcInspector { boolean result=true; if (this.restreint){ RoadInformation.RoadType type=arc.getRoadInformation().getType(); - if (type==RoadInformation.RoadType.PEDESTRIAN || type==RoadInformation.RoadType.CYCLEWAY ) { + if (type != RoadInformation.RoadType.MOTORWAY && + type != RoadInformation.RoadType.TRUNK && + type != RoadInformation.RoadType.PRIMARY && + type != RoadInformation.RoadType.SECONDARY && + type != RoadInformation.RoadType.TERTIARY && + type != RoadInformation.RoadType.RESIDENTIAL && + type != RoadInformation.RoadType.UNCLASSIFIED ) { result=false; } } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java index 4db278f..29df1a0 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java @@ -9,7 +9,8 @@ public class AStarAlgorithm extends DijkstraAlgorithm { @Override protected LabelStar createLabel(Node node) { - return new LabelStar(node, false, Double.POSITIVE_INFINITY, null, getInputData().getDestination()); + ShortestPathData data = getInputData(); //pour récupérer la vitesse maximale du graphe, la destination et si on est en fastestpath ou shortestpath + return new LabelStar(node, false, Double.POSITIVE_INFINITY,null,data); } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelProblemeOuvert.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelProblemeOuvert.java index 798459c..c3355fe 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelProblemeOuvert.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelProblemeOuvert.java @@ -2,6 +2,7 @@ package org.insa.graphs.algorithm.shortestpath; import org.insa.graphs.model.Arc; import org.insa.graphs.model.Node; +<<<<<<< HEAD public class LabelProblemeOuvert extends Label { private double batteryLeft; //double pour la cohérence avec les autres couts qui sont en double eux aussi @@ -23,4 +24,31 @@ public class LabelProblemeOuvert extends Label { public double getTotalCost() { //pourquoi getTotalCost ? psq il est utilisé dans le compareTo return this.getCoutRealise(); } +======= +public class LabelProblemeOuvert extends Label { + private double autonomieRestante; //double pour la cohérence avec les autres couts qui sont en double eux aussi + + public LabelProblemeOuvert(Node sommet, boolean marque, double cout, Arc pere, double autonomieRestante) { + super(sommet, marque, cout, pere); + this.autonomieRestante = autonomieRestante; + } + + public double getAutonomieRestante() { + return autonomieRestante; + } + + public void setAutonomieRestante(double autonomieRestante) { + this.autonomieRestante = autonomieRestante; + } + + @Override + public double getTotalCost() { //normalement pas besoin + return this.getCoutRealise(); + } + + /*@Override + public int compareTo(LabelProblemeOuvert other) { + return Double.compare(this.getTotalCost(), other.getTotalCost()); + }*/ +>>>>>>> 1aee5a57c3b4966b14ac38a33ed9e52af7a882d0 } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java index 3ebdc92..88a9240 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/LabelStar.java @@ -1,5 +1,6 @@ package org.insa.graphs.algorithm.shortestpath; +import org.insa.graphs.algorithm.AbstractInputData; import org.insa.graphs.model.Arc; import org.insa.graphs.model.Node; import org.insa.graphs.model.Point; @@ -7,30 +8,70 @@ import org.insa.graphs.model.Point; public class LabelStar extends Label { - - private Node destination; - public LabelStar(Node sommetCourant, Boolean marque, double coutRealise, Arc pere,Node destination) { +; + private ShortestPathData pathData; + public LabelStar(Node sommetCourant, Boolean marque, double coutRealise, Arc pere, ShortestPathData data) { super(sommetCourant, marque, coutRealise, pere); - this.destination=destination; + this.pathData = data; //pour récupérer la vitesse maximale du graphe, la destination et si on est en fastestpath ou shortestpath } //pour optimiser l'algo : ATTENTION PAS à L'initialisation pas le faire sinon ça va le faire pr tout les pts //on rajoute un paremètre distance ds le label et quand on passe sur le label si c'est linfini on le calcule - @Override + /*@Override public double getTotalCost() { //pourquoi getTotalCost ? psq il est utilisé dans le compareTo //System.out.println("cout realise : " + getCoutRealise()+ "\n distance : "distance(getSommetCourant().getPoint(),this.destination.getPoint())); double cout=getCoutRealise(); - Point calcul = this.destination.getPoint(); + Point calcul = this.pathData.getDestination().getPoint(); cout+=calcul.distanceTo(this.getSommetCourant().getPoint()); return (cout); - } + }*/ //pas nécessaire normalement /*public int compareTo(LabelStar other) { return Double.compare(this.getTotalCost(), other.getTotalCost()); }*/ + /** + * Calcule le coût total estimé (f = g + h) pour l'algorithme A*. + * g (getCoutRealise()) est le coût actuel depuis le départ. + * h est l'heuristique : + * - En mode DISTANCE: distance à vol d'oiseau (via distanceTo) jusqu'à la destination. + * - En mode TEMPS: distance à vol d'oiseau (via distanceTo) / vitesse maximale sur le graphe. + * @return Le coût total estimé. + */ + @Override + public double getTotalCost() { + double gCost = getCoutRealise(); // Coût actuel depuis l'origine (distance ou temps) + double hCost = 0.0; + + Node current = getSommetCourant(); + Node destinationNode = this.pathData.getDestination(); // Obtention de la destination depuis pathData + Point currentPoint = current.getPoint(); + Point destinationPoint = destinationNode.getPoint(); + if (currentPoint == null || destinationPoint == null) { + return gCost; // Heuristique nulle si points non valides + } + + //calcul vol d'oiseau + double distanceToDestinationMeters = currentPoint.distanceTo(destinationPoint); + + //différencier TIME et DISTANCE + if (this.pathData.getMode() == AbstractInputData.Mode.TIME) { + int maxSpeedKmH = this.pathData.getGraph().getGraphInformation().getMaximumSpeed(); + + // Conversion de la vitesse max en mètres par seconde (m/s) + double maxSpeedMpS = maxSpeedKmH / 3.6; + hCost = distanceToDestinationMeters / maxSpeedMpS; // hCost est maintenant en secondes + + } else { + // Heuristique pour le mode DISTANCE (ou par défaut) + hCost = distanceToDestinationMeters; // hCost est en mètres + } + + return gCost + hCost; + } + } \ No newline at end of file diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java index 3466b03..d180d8c 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/ProblemeOuvert.java @@ -105,13 +105,25 @@ gérer le problème de la recharge, quand la faire ? package org.insa.graphs.algorithm.shortestpath; +<<<<<<< HEAD +======= +import java.util.ArrayList; +import java.util.Collections; + +>>>>>>> 1aee5a57c3b4966b14ac38a33ed9e52af7a882d0 import org.insa.graphs.algorithm.AbstractSolution.Status; import org.insa.graphs.algorithm.utils.BinaryHeap; import org.insa.graphs.model.Arc; import org.insa.graphs.model.Graph; import org.insa.graphs.model.Node; +<<<<<<< HEAD import org.insa.graphs.model.RoadInformation.RoadType; +======= +import org.insa.graphs.model.Path; +import org.insa.graphs.model.RoadInformation.RoadType; +//import org.insa.graphs.algorithm.shortestpath.ProblemeOuvert; +>>>>>>> 1aee5a57c3b4966b14ac38a33ed9e52af7a882d0 public class ProblemeOuvert extends DijkstraAlgorithm { @@ -127,6 +139,7 @@ public class ProblemeOuvert extends DijkstraAlgorithm { return new LabelProblemeOuvert(node, false, Double.POSITIVE_INFINITY, null, MAX_BATTERY); } +<<<<<<< HEAD // Surcharge pour compatibilité avec DijkstraAlgorithm @Override protected void tryUpdateLabel(Label[] labels, BinaryHeap