on complete le test dijkstra
Questo commit è contenuto in:
parent
773a14154f
commit
4639211ea4
5 ha cambiato i file con 44 aggiunte e 29 eliminazioni
1
.~lock.probleme_ouvert_voiture_elec.odt#
File normale
1
.~lock.probleme_ouvert_voiture_elec.odt#
File normale
|
|
@ -0,0 +1 @@
|
||||||
|
,bezza,insa-10821,20.05.2025 11:05,file:///home/bezza/.config/libreoffice/4;
|
||||||
|
|
@ -2,38 +2,45 @@ package org.insa.graphs.algorithm;
|
||||||
|
|
||||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||||
import org.insa.graphs.model.Arc;
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.RoadInformation;
|
||||||
|
|
||||||
public class MyArcInspector implements ArcInspector {
|
public class MyArcInspector implements ArcInspector {
|
||||||
|
|
||||||
private final Mode mode;
|
private final Mode mode;
|
||||||
private final int maxSpeed;
|
private final int maxSpeed;
|
||||||
|
private final boolean restreint;
|
||||||
// Constructeur qui prend en paramètre le mode de transport (TIME ou LENGTH) et la vitesse maximale.
|
// restreint sert à savoir si le user veut restreindre le path à des chemins uniquement accessible en voiture.
|
||||||
public MyArcInspector(Mode mode, int maxSpeed) {
|
public MyArcInspector(Mode mode, int maxSpeed,boolean restreint) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.maxSpeed = maxSpeed;
|
this.maxSpeed = maxSpeed;
|
||||||
|
this.restreint=restreint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAllowed(Arc arc) {
|
public boolean isAllowed(Arc arc) {
|
||||||
// Ici vous pouvez définir des critères personnalisés pour autoriser ou interdire un arc
|
boolean result=true;
|
||||||
// Par exemple, vous pouvez filtrer selon le type de transport ou d'autres critères
|
if (this.restreint){
|
||||||
return true; // Par défaut, nous autorisons tous les arcs
|
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
|
@Override
|
||||||
public double getCost(Arc arc) {
|
public double getCost(Arc arc) {
|
||||||
if (mode == Mode.LENGTH) {
|
if (mode == Mode.LENGTH) {
|
||||||
// Calcul du coût basé sur la longueur de l'arc (en mètres, par exemple)
|
// Calcul du coût sur la longueur de l'arc
|
||||||
return arc.getLength();
|
return (double)arc.getLength();
|
||||||
} else if (mode == Mode.TIME) {
|
} else{
|
||||||
// Calcul du coût basé sur le temps de parcours
|
// Calcul du coût 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 lengthInMeters = arc.getLength();
|
||||||
double speedInMetersPerSecond = maxSpeed / 3.6; // convertir la vitesse en m/s
|
double speedInMetersPerSecond = maxSpeed / 3.6;
|
||||||
return lengthInMeters / speedInMetersPerSecond; // Temps = Distance / Vitesse
|
return lengthInMeters / speedInMetersPerSecond;
|
||||||
}
|
}
|
||||||
return Double.POSITIVE_INFINITY; // En cas d'erreur
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// avant de le mettre à jour
|
// avant de le mettre à jour
|
||||||
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||||
heap.remove(succLabel);
|
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.setCoutRealise(newCost);
|
||||||
succLabel.setPere(arc);
|
succLabel.setPere(arc);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ public class TestDijkstra {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fonction pour tester un scénario
|
// 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 Graph graph;
|
||||||
final Path path;
|
final Path path;
|
||||||
int maxSpeed = 130; // La vitesse maximale en km/h
|
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);
|
ShortestPathData data = new ShortestPathData(graph, origin, destination, arcInspector);
|
||||||
DijkstraAlgorithm dijkstra;
|
DijkstraAlgorithm dijkstra;
|
||||||
if (Astar) {
|
if (Astar) {
|
||||||
|
|
@ -145,9 +145,9 @@ public class TestDijkstra {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Affichage graphique
|
// Affichage graphique
|
||||||
/* final Drawing drawing = createDrawing();
|
// final Drawing drawing = createDrawing();
|
||||||
drawing.drawGraph(graph);
|
// drawing.drawGraph(graph);
|
||||||
drawing.drawPath(path); */
|
// drawing.drawPath(path);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Aucun chemin trouvé.");
|
System.out.println("Aucun chemin trouvé.");
|
||||||
|
|
@ -156,22 +156,28 @@ public class TestDijkstra {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
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 ==");
|
//cartes non routières
|
||||||
testScenario("carre.mapgr", 0, 9999, Mode.LENGTH, true,false);
|
// 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
|
//cartes routières
|
||||||
System.out.println("== Test en distance ==");
|
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 ==");
|
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
|
// autres scénarios
|
||||||
|
|
||||||
System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
// System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
||||||
testScenario("bretagne.mapgr",48233,135047 , Mode.TIME, false,false);
|
// 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
probleme_ouvert_voiture_elec.odt
File normale
BIN
probleme_ouvert_voiture_elec.odt
File normale
File binario non mostrato.
Caricamento…
Crea riferimento in una nuova segnalazione