ajout de Launch
This commit is contained in:
parent
f18142fdf8
commit
f95ded7b24
2 changed files with 49 additions and 21 deletions
|
@ -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
|
||||||
|
try (final PathReader pathReader = new BinaryPathReader(new DataInputStream(
|
||||||
|
new BufferedInputStream(new FileInputStream(pathName))))) {
|
||||||
|
|
||||||
// TODO: create a path reader
|
// TODO: read the pathxx
|
||||||
try (final PathReader pathReader = null) {
|
path = pathReader.readPath(graph);
|
||||||
|
|
||||||
// TODO: read the path
|
|
||||||
path = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: draw the path on the drawing
|
// TODO: draw the path on the drawing
|
||||||
|
drawing.drawPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -40,7 +41,7 @@ public class Path {
|
||||||
// ne faut pas throw une erreur mais return un chemin vide.
|
// ne faut pas throw une erreur mais return un chemin vide.
|
||||||
}
|
}
|
||||||
if (nodes.size() == 1) {
|
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<>();
|
ArrayList<Arc> finalList = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -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,27 +118,47 @@ 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 */
|
/*
|
||||||
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(
|
throw new IllegalArgumentException(
|
||||||
"les nodes de la liste ne sont pas connectés \n");
|
"les nodes de la liste ne sont pas connectés \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue