forked from lebotlan/BE-Graphes
Merge branch 'main' of https://git.etud.insa-toulouse.fr/ymahe/BE-Graphes-MAHE-MOLL
This commit is contained in:
commit
a9165c3bfc
2 changed files with 48 additions and 13 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,26 @@ 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
|
// DONE: read the graph
|
||||||
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
|
// DONE: draw the graph on the drawing
|
||||||
|
drawing.drawGraph(graph);
|
||||||
|
|
||||||
// TODO: create a path reader
|
// DONE: 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
|
// DONE: read the path
|
||||||
path = null;
|
path = pathReader.readPath(graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: draw the path on the drawing
|
// DONE: draw the path on the drawing
|
||||||
|
drawing.drawPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|
@ -26,12 +27,32 @@ public class Path {
|
||||||
* @return A path that goes through the given list of nodes.
|
* @return A path that goes through the given list of nodes.
|
||||||
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
||||||
* consecutive nodes in the list are not connected in the graph.
|
* consecutive nodes in the list are not connected in the graph.
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
// TODO:
|
|
||||||
|
if (nodes.size() == 1) { return new Path(graph, nodes.get(0)); }
|
||||||
|
|
||||||
|
for (int i = 0; i < nodes.size() - 1; i++) {
|
||||||
|
Arc bestArc = null;
|
||||||
|
double bestSpeed = Double.MAX_VALUE;
|
||||||
|
for (Arc arcsucc : nodes.get(i).getSuccessors()) {
|
||||||
|
if (arcsucc.getDestination().equals(nodes.get(i+1))) {
|
||||||
|
int succspeed = arcsucc.getRoadInformation().getMaximumSpeed();
|
||||||
|
if (arcsucc.getTravelTime(succspeed) < bestSpeed) {
|
||||||
|
bestArc = arcsucc;
|
||||||
|
bestSpeed = arcsucc.getTravelTime(succspeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bestArc == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
} else {
|
||||||
|
arcs.add(bestArc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Path(graph, arcs);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,11 +214,21 @@ public class Path {
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return true if the path is valid, false otherwise.
|
* @return true if the path is valid, false otherwise.
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
// TODO:
|
|
||||||
return false;
|
if (this.isEmpty()) { return true; }
|
||||||
|
if (this.size() == 1 && this.arcs.isEmpty()) { return true; }
|
||||||
|
if (!this.arcs.get(0).getOrigin().equals(this.origin)) { return false; }
|
||||||
|
|
||||||
|
Boolean good = true;
|
||||||
|
for (int i = 0; i < this.arcs.size() - 1; i++) {
|
||||||
|
if (!this.arcs.get(i).getDestination().equals(this.arcs.get(i+1).getOrigin())) {
|
||||||
|
good = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return good;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue