ajout de Launch
Questo commit è contenuto in:
parent
f18142fdf8
commit
f95ded7b24
2 ha cambiato i file con 49 aggiunte e 21 eliminazioni
|
@ -14,6 +14,7 @@ import org.insa.graphs.gui.drawing.components.BasicDrawing;
|
|||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Path;
|
||||
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.PathReader;
|
||||
|
||||
|
@ -57,23 +58,25 @@ public class Launch {
|
|||
try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(mapName))))) {
|
||||
|
||||
// TODO: read the graph
|
||||
graph = null;
|
||||
// TODO: read the graph xxx
|
||||
graph = reader.read();
|
||||
}
|
||||
|
||||
// create the drawing
|
||||
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
|
||||
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(pathName))))) {
|
||||
|
||||
// TODO: create a path reader
|
||||
try (final PathReader pathReader = null) {
|
||||
|
||||
// TODO: read the path
|
||||
path = null;
|
||||
// TODO: read the pathxx
|
||||
path = pathReader.readPath(graph);
|
||||
}
|
||||
|
||||
// TODO: draw the path on the drawing
|
||||
drawing.drawPath(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
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.Collections;
|
||||
|
@ -40,7 +41,7 @@ public class Path {
|
|||
// ne faut pas throw une erreur mais return un chemin vide.
|
||||
}
|
||||
if (nodes.size() == 1) {
|
||||
return new Path(graph, nodes.get(0)); /* chemin de 1 point(node) */
|
||||
return new Path(graph, nodes.get(0)); /* chemin de 1 point(node) */
|
||||
}
|
||||
ArrayList<Arc> finalList = new ArrayList<>();
|
||||
|
||||
|
@ -105,7 +106,11 @@ public class Path {
|
|||
else {
|
||||
|
||||
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
|
||||
|
@ -113,27 +118,47 @@ public class Path {
|
|||
List<Arc> temporaryArcs = nodeE.getSuccessors();
|
||||
List<Arc> temporaryCorrespondingArc = new ArrayList<>();
|
||||
for (Arc arcE : temporaryArcs) {
|
||||
if (arcE.getDestination()
|
||||
.equals(nodes.get(nodes.indexOf(nodeE) + 1))) { /*si la destination de l'arc est égal au prochain node*/
|
||||
temporaryCorrespondingArc.add(arcE);/* ajouter cet arc dans la liste temporaryCorrespondingArcs*/
|
||||
if (arcE.getDestination().equals(nodes.get(nodes.indexOf(nodeE)
|
||||
+ 1))) { /*
|
||||
* 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 */
|
||||
if (temporaryCorrespondingArc.isEmpty()) {
|
||||
/*
|
||||
* la liste temporaryCorrespondingArc devrait être remplie si elle
|
||||
* est vide les 2 nodes ne sont pas connectés
|
||||
*/
|
||||
if (temporaryCorrespondingArc.isEmpty()) {
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
"les nodes de la liste ne sont pas connectés \n");
|
||||
}
|
||||
|
||||
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()) {
|
||||
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()) {
|
||||
|
@ -315,9 +340,9 @@ public class Path {
|
|||
* @return Total length of the path (in meters).
|
||||
*/
|
||||
public float getLength() {
|
||||
float pathLength=0f; // sinon error si on met O.O
|
||||
for (Arc element : this.arcs) {
|
||||
pathLength=pathLength+((float) element.getLength());
|
||||
float pathLength = 0f; // sinon error si on met O.O
|
||||
for (Arc element : this.arcs) {
|
||||
pathLength = pathLength + ((float) element.getLength());
|
||||
}
|
||||
return pathLength;
|
||||
}
|
||||
|
|
Caricamento…
Crea riferimento in una nuova segnalazione