ajout de Launch

This commit is contained in:
Bezza Younes 2025-04-29 16:07:13 +02:00
parent f18142fdf8
commit f95ded7b24
2 changed files with 49 additions and 21 deletions

View file

@ -14,6 +14,7 @@ import org.insa.graphs.gui.drawing.components.BasicDrawing;
import org.insa.graphs.model.Graph; import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Path; import org.insa.graphs.model.Path;
import org.insa.graphs.model.io.BinaryGraphReader; import org.insa.graphs.model.io.BinaryGraphReader;
import org.insa.graphs.model.io.BinaryPathReader;
import org.insa.graphs.model.io.GraphReader; import org.insa.graphs.model.io.GraphReader;
import org.insa.graphs.model.io.PathReader; import org.insa.graphs.model.io.PathReader;
@ -57,23 +58,25 @@ public class Launch {
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream( try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
new BufferedInputStream(new FileInputStream(mapName))))) { new BufferedInputStream(new FileInputStream(mapName))))) {
// TODO: read the graph // TODO: read the graph xxx
graph = null; graph = reader.read();
} }
// create the drawing // create the drawing
final Drawing drawing = createDrawing(); final Drawing drawing = createDrawing();
// TODO: draw the graph on the drawing // TODO: draw the graph on the drawing xxx
drawing.drawGraph(graph);
// TODO: create a path reader // TODO: create a path reader
try (final PathReader pathReader = null) { try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
new BufferedInputStream(new FileInputStream(pathName))))) {
// TODO: read the path // TODO: read the pathxx
path = null; path = pathReader.readPath(graph);
} }
// TODO: draw the path on the drawing // TODO: draw the path on the drawing
drawing.drawPath(path);
} }
} }

View file

@ -1,6 +1,7 @@
package org.insa.graphs.model; package org.insa.graphs.model;
import java.awt.RenderingHints; //commenté parce qu'il soulevait une erreur (doesn't exist) import java.awt.RenderingHints; // commenté parce qu'il soulevait une erreur (doesn't
// exist)
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -105,7 +106,11 @@ public class Path {
else { else {
for (Node nodeE : nodes) { for (Node nodeE : nodes) {
if (nodes.indexOf(nodeE) == nodes.size() - 1) { /* on ne regarde pas le dernier node qui est la destination */ if (nodes.indexOf(nodeE) == nodes.size()
- 1) { /*
* on ne regarde pas le dernier node qui est la
* destination
*/
} // sinon on fait notre recherche } // sinon on fait notre recherche
@ -113,14 +118,24 @@ public class Path {
List<Arc> temporaryArcs = nodeE.getSuccessors(); List<Arc> temporaryArcs = nodeE.getSuccessors();
List<Arc> temporaryCorrespondingArc = new ArrayList<>(); List<Arc> temporaryCorrespondingArc = new ArrayList<>();
for (Arc arcE : temporaryArcs) { for (Arc arcE : temporaryArcs) {
if (arcE.getDestination() if (arcE.getDestination().equals(nodes.get(nodes.indexOf(nodeE)
.equals(nodes.get(nodes.indexOf(nodeE) + 1))) { /*si la destination de l'arc est égal au prochain node*/ + 1))) { /*
temporaryCorrespondingArc.add(arcE);/* ajouter cet arc dans la liste temporaryCorrespondingArcs*/ * si la destination de l'arc est égal au
* prochain node
*/
temporaryCorrespondingArc
.add(arcE);/*
* ajouter cet arc dans la liste
* temporaryCorrespondingArcs
*/
} }
} }
/* la liste temporaryCorrespondingArc devrait être remplie si elle est vide les 2 nodes ne sont pas connectés */ /*
* la liste temporaryCorrespondingArc devrait être remplie si elle
* est vide les 2 nodes ne sont pas connectés
*/
if (temporaryCorrespondingArc.isEmpty()) { if (temporaryCorrespondingArc.isEmpty()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -128,12 +143,22 @@ public class Path {
} }
Arc ArcPlusCourt = temporaryCorrespondingArc.get(0); Arc ArcPlusCourt = temporaryCorrespondingArc.get(0);
for (Arc ArcTemporaire : temporaryCorrespondingArc) {/*comparer tous les arcs de la liste et prendre le plus rapide */ for (Arc ArcTemporaire : temporaryCorrespondingArc) {/*
* comparer
* tous les
* arcs de la
* liste et
* prendre le
* plus rapide
*/
if (ArcTemporaire.getLength() < ArcPlusCourt.getLength()) { if (ArcTemporaire.getLength() < ArcPlusCourt.getLength()) {
ArcPlusCourt = ArcTemporaire; ArcPlusCourt = ArcTemporaire;
} }
} }
arcsFinaux.add(ArcPlusCourt);/*l'ajouter dans la liste finale qui est arcsFinaux */ arcsFinaux.add(ArcPlusCourt);/*
* l'ajouter dans la liste finale qui
* est arcsFinaux
*/
} }
else if (!nodeE.hasSuccessors()) { else if (!nodeE.hasSuccessors()) {
@ -315,9 +340,9 @@ public class Path {
* @return Total length of the path (in meters). * @return Total length of the path (in meters).
*/ */
public float getLength() { public float getLength() {
float pathLength=0f; // sinon error si on met O.O float pathLength = 0f; // sinon error si on met O.O
for (Arc element : this.arcs) { for (Arc element : this.arcs) {
pathLength=pathLength+((float) element.getLength()); pathLength = pathLength + ((float) element.getLength());
} }
return pathLength; return pathLength;
} }