on complete le test dijkstra

This commit is contained in:
bezza 2025-05-20 13:33:57 +02:00
parent 773a14154f
commit 4639211ea4
5 changed files with 44 additions and 29 deletions

View file

@ -0,0 +1 @@
,bezza,insa-10821,20.05.2025 11:05,file:///home/bezza/.config/libreoffice/4;

View file

@ -2,38 +2,45 @@ package org.insa.graphs.algorithm;
import org.insa.graphs.algorithm.AbstractInputData.Mode;
import org.insa.graphs.model.Arc;
import org.insa.graphs.model.RoadInformation;
public class MyArcInspector implements ArcInspector {
private final Mode mode;
private final int maxSpeed;
// Constructeur qui prend en paramètre le mode de transport (TIME ou LENGTH) et la vitesse maximale.
public MyArcInspector(Mode mode, int maxSpeed) {
private final boolean restreint;
// restreint sert à savoir si le user veut restreindre le path à des chemins uniquement accessible en voiture.
public MyArcInspector(Mode mode, int maxSpeed,boolean restreint) {
this.mode = mode;
this.maxSpeed = maxSpeed;
this.restreint=restreint;
}
@Override
public boolean isAllowed(Arc arc) {
// Ici vous pouvez définir des critères personnalisés pour autoriser ou interdire un arc
// Par exemple, vous pouvez filtrer selon le type de transport ou d'autres critères
return true; // Par défaut, nous autorisons tous les arcs
boolean result=true;
if (this.restreint){
RoadInformation.RoadType type=arc.getRoadInformation().getType();
if (type==RoadInformation.RoadType.PEDESTRIAN || type==RoadInformation.RoadType.CYCLEWAY ) {
result=false;
}
}
return result; // On autorise tous les arcs sinon ceux uniquement en voiture si restreint.
}
@Override
public double getCost(Arc arc) {
if (mode == Mode.LENGTH) {
// Calcul du coût basé sur la longueur de l'arc (en mètres, par exemple)
return arc.getLength();
} else if (mode == Mode.TIME) {
// Calcul du coût basé sur le temps de parcours
// Le temps est calculé comme distance / vitesse maximale
double lengthInMeters = arc.getLength(); // longueur de l'arc en mètres
double speedInMetersPerSecond = maxSpeed / 3.6; // convertir la vitesse en m/s
return lengthInMeters / speedInMetersPerSecond; // Temps = Distance / Vitesse
// Calcul du coût sur la longueur de l'arc
return (double)arc.getLength();
} else{
// Calcul du coût sur le temps de parcours
double lengthInMeters = arc.getLength();
double speedInMetersPerSecond = maxSpeed / 3.6;
return lengthInMeters / speedInMetersPerSecond;
}
return Double.POSITIVE_INFINITY; // En cas d'erreur
}
@Override

View file

@ -76,6 +76,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// avant de le mettre à jour
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
heap.remove(succLabel);
System.out.println(succLabel.getCoutRealise());// print de confirmation , pour verif si tous les couts qui sortent du tas sont croissant. getTotalcost pas croissant!!
}
succLabel.setCoutRealise(newCost);
succLabel.setPere(arc);

View file

@ -46,7 +46,7 @@ public class TestDijkstra {
}
// fonction pour tester un scénario
public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, boolean Astar) throws Exception {
public static void testScenario(String map, int depart, int arrivee, Mode mode, boolean petitGraphe, boolean Astar, boolean restreint) throws Exception {
final Graph graph;
final Path path;
int maxSpeed = 130; // La vitesse maximale en km/h
@ -64,7 +64,7 @@ public class TestDijkstra {
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed);
ArcInspector arcInspector = new MyArcInspector(mode, maxSpeed,restreint);
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
DijkstraAlgorithm dijkstra;
if (Astar) {
@ -145,9 +145,9 @@ public class TestDijkstra {
}
// Affichage graphique
/* final Drawing drawing = createDrawing();
drawing.drawGraph(graph);
drawing.drawPath(path); */
// final Drawing drawing = createDrawing();
// drawing.drawGraph(graph);
// drawing.drawPath(path);
} else {
System.out.println("Aucun chemin trouvé.");
@ -156,22 +156,28 @@ public class TestDijkstra {
}
public static void main(String[] args) throws Exception {
//cartes non routières
System.out.println("== Chemin de longueur nulle ==");
testScenario("carre.mapgr", 9, 9, Mode.LENGTH, true,false);
System.out.println("== Sommet hors du graphe ==");
testScenario("carre.mapgr", 0, 9999, Mode.LENGTH, true,false);
//cartes non routières
// System.out.println("== Chemin de longueur nulle ==");
// testScenario("carre.mapgr", 9, 9, Mode.LENGTH, true,false,false);
// System.out.println("== Sommet hors du graphe ==");
// testScenario("carre.mapgr", 0, 9999, Mode.LENGTH, true,false,false);
//cartes routières
System.out.println("== Test en distance ==");
testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,false);
testScenario("insa.mapgr", 369, 838, Mode.LENGTH, true,false,false);
System.out.println("== Test en temps ==");
testScenario("insa.mapgr", 369, 838, Mode.TIME, true,false);
testScenario("insa.mapgr", 369, 838, Mode.TIME, true,false,false);
// autres scénarios
System.out.println("== Trajet long (et pénible avec les enfants) ==");
testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false,false);
// System.out.println("== Trajet long (et pénible avec les enfants) ==");
// testScenario("bretagne.mapgr",564429,602395 , Mode.LENGTH, false,false,false);
// System.out.println("== Trajet impossible (piste cyclable) ==");
// testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,true); //marche pas
}
}

Binary file not shown.