Compare commits
No commits in common. "5a1402bc1df944b9df1c675f2d2816d03ba574a8" and "52df139bd81e14b9803c93c91ef6d8e86ff27ac8" have entirely different histories.
5a1402bc1d
...
52df139bd8
2 changed files with 49 additions and 90 deletions
|
|
@ -72,7 +72,6 @@ import org.insa.graphs.model.io.BinaryPathReader;
|
|||
import org.insa.graphs.model.io.GraphReader;
|
||||
import org.insa.graphs.model.io.MapMismatchException;
|
||||
|
||||
|
||||
public class MainWindow extends JFrame {
|
||||
|
||||
/**
|
||||
|
|
@ -83,7 +82,7 @@ public class MainWindow extends JFrame {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
private static final String WINDOW_TITLE = "CC la famille";
|
||||
private static final String WINDOW_TITLE = "BE Graphes INSA";
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -345,7 +344,7 @@ public class MainWindow extends JFrame {
|
|||
|
||||
JTextArea infoPanel = new JTextArea();
|
||||
infoPanel.setMinimumSize(new Dimension(200, 50));
|
||||
// infoPanel.setBackground(Color.WHITE);
|
||||
infoPanel.setBackground(Color.WHITE);
|
||||
infoPanel.setLineWrap(true);
|
||||
infoPanel.setEditable(false);
|
||||
this.logStream = new StreamCapturer(infoPanel);
|
||||
|
|
@ -378,7 +377,7 @@ public class MainWindow extends JFrame {
|
|||
mainPanel.setResizeWeight(0.8);
|
||||
mainPanel.setDividerSize(5);
|
||||
|
||||
// mainPanel.setBackground(Color.WHITE);
|
||||
mainPanel.setBackground(Color.WHITE);
|
||||
mainPanel.setLeftComponent(openPanel);
|
||||
mainPanel.setRightComponent(rightComponent);
|
||||
this.add(mainPanel, BorderLayout.CENTER);
|
||||
|
|
@ -845,16 +844,7 @@ public class MainWindow extends JFrame {
|
|||
|
||||
// Try to set system look and feel.
|
||||
try {
|
||||
boolean isThemeSet = false;
|
||||
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
|
||||
if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(info.getClassName())) {
|
||||
UIManager.setLookAndFeel(info.getClassName());
|
||||
isThemeSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isThemeSet)
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,105 +8,68 @@ import java.util.List;
|
|||
* <p>
|
||||
* Class representing a path between nodes in a graph.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* A path is represented as a list of {@link Arc} with an origin and not a list
|
||||
* of {@link Node} due to the multi-graph nature (multiple arcs between two
|
||||
* nodes) of the considered graphs.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
public class Path {
|
||||
|
||||
/**
|
||||
* Create a new path that goes through the given list of nodes (in order),
|
||||
* choosing the fastest route if multiple are available.
|
||||
*
|
||||
*
|
||||
* @param graph Graph containing the nodes in the list.
|
||||
* @param nodes List of nodes to build the path.
|
||||
*
|
||||
* @return A path that goes through the given list of nodes.
|
||||
*
|
||||
* @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)
|
||||
throws IllegalArgumentException {
|
||||
return Path.createSmallestPath(graph, nodes, false);
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
// TODO:
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new path that goes through the given list of nodes (in order),
|
||||
* choosing the shortest route if multiple are available.
|
||||
*
|
||||
*
|
||||
* @param graph Graph containing the nodes in the list.
|
||||
* @param nodes List of nodes to build the path.
|
||||
*
|
||||
* @return A path that goes through the given list of nodes.
|
||||
*
|
||||
* @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 createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
||||
throws IllegalArgumentException {
|
||||
return Path.createSmallestPath(graph, nodes, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new path that goes through the given list of nodes (in order),
|
||||
* choosing the shortest or fastest route if multiple are available.
|
||||
*
|
||||
* @param graph Graph containing the nodes in the list.
|
||||
* @param nodes List of nodes to build the path.
|
||||
* @param isLength Should we search the shortest path (true) or the fastest path (false)
|
||||
* @return A path that goes through the given list of nodes.
|
||||
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
||||
* consecutive nodes in the list are not connected in the graph.
|
||||
*/
|
||||
private static Path createSmallestPath(Graph graph, List<Node> nodes, boolean isLength) {
|
||||
List<Arc> arcs = new ArrayList<>();
|
||||
if (nodes.size() != 0 && nodes.size() != 1) {
|
||||
for (int i = 0; i < (nodes.size() - 1); i++) {
|
||||
Arc shortest = Path.getSmallestArc(
|
||||
nodes.get(i).getSuccessors(), nodes.get(i + 1), isLength
|
||||
);
|
||||
arcs.add(shortest);
|
||||
}
|
||||
} else if (nodes.size() == 1)
|
||||
return new Path(graph, nodes.get(0));
|
||||
List<Arc> arcs = new ArrayList<Arc>();
|
||||
// TODO:
|
||||
return new Path(graph, arcs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the smallest arc in the given list.
|
||||
* If an arc destination does not match the given node, it is ignored.
|
||||
*
|
||||
* @param arcs The arcs list to search in
|
||||
* @param nextNode The next node to match the arc destination
|
||||
* @param isLength Should we search the shortest arc (true) or the fastest arc (false)
|
||||
* @return The smallest arc to nextNode
|
||||
* @throws IllegalArgumentException If no node is found
|
||||
*/
|
||||
private static Arc getSmallestArc(List<Arc> arcs, Node nextNode, boolean isLength) {
|
||||
Arc shortestArc = null;
|
||||
double smallestComparator = -1;
|
||||
for (Arc arc : arcs) {
|
||||
if (nextNode.equals(arc.getDestination())) {
|
||||
double comparator = isLength ? arc.getLength() : arc.getMinimumTravelTime();
|
||||
if (comparator < smallestComparator || smallestComparator < 0) {
|
||||
smallestComparator = comparator;
|
||||
shortestArc = arc;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shortestArc == null)
|
||||
throw new IllegalArgumentException();
|
||||
return shortestArc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate the given paths.
|
||||
*
|
||||
*
|
||||
* @param paths Array of paths to concatenate.
|
||||
*
|
||||
* @return Concatenated path.
|
||||
*
|
||||
* @throws IllegalArgumentException if the paths cannot be concatenated (IDs of
|
||||
* map do not match, or the end of a path is not the beginning of the
|
||||
* next).
|
||||
* map do not match, or the end of a path is not the beginning of the
|
||||
* next).
|
||||
*/
|
||||
public static Path concatenate(Path... paths) throws IllegalArgumentException {
|
||||
if (paths.length == 0) {
|
||||
|
|
@ -120,7 +83,7 @@ public class Path {
|
|||
}
|
||||
}
|
||||
ArrayList<Arc> arcs = new ArrayList<>();
|
||||
for (Path path : paths) {
|
||||
for (Path path: paths) {
|
||||
arcs.addAll(path.getArcs());
|
||||
}
|
||||
Path path = new Path(paths[0].getGraph(), arcs);
|
||||
|
|
@ -142,7 +105,7 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Create an empty path corresponding to the given graph.
|
||||
*
|
||||
*
|
||||
* @param graph Graph containing the path.
|
||||
*/
|
||||
public Path(Graph graph) {
|
||||
|
|
@ -153,9 +116,9 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Create a new path containing a single node.
|
||||
*
|
||||
*
|
||||
* @param graph Graph containing the path.
|
||||
* @param node Single node of the path.
|
||||
* @param node Single node of the path.
|
||||
*/
|
||||
public Path(Graph graph, Node node) {
|
||||
this.graph = graph;
|
||||
|
|
@ -165,9 +128,9 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Create a new path with the given list of arcs.
|
||||
*
|
||||
*
|
||||
* @param graph Graph containing the path.
|
||||
* @param arcs Arcs to construct the path.
|
||||
* @param arcs Arcs to construct the path.
|
||||
*/
|
||||
public Path(Graph graph, List<Arc> arcs) {
|
||||
this.graph = graph;
|
||||
|
|
@ -205,7 +168,7 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Check if this path is empty (it does not contain any node).
|
||||
*
|
||||
*
|
||||
* @return true if this path is empty, false otherwise.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
|
|
@ -214,7 +177,7 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Get the number of <b>nodes</b> in this path.
|
||||
*
|
||||
*
|
||||
* @return Number of nodes in this path.
|
||||
*/
|
||||
public int size() {
|
||||
|
|
@ -223,7 +186,7 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Check if this path is valid.
|
||||
* <p>
|
||||
*
|
||||
* A path is valid if any of the following is true:
|
||||
* <ul>
|
||||
* <li>it is empty;</li>
|
||||
|
|
@ -232,8 +195,10 @@ public class Path {
|
|||
* consecutive arcs, the destination of the first one is the origin of the
|
||||
* second one.</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @return true if the path is valid, false otherwise.
|
||||
*
|
||||
* @deprecated Need to be implemented.
|
||||
*/
|
||||
public boolean isValid() {
|
||||
boolean valid = isEmpty() || (this.arcs.size() == 0 && this.origin != null);
|
||||
|
|
@ -241,7 +206,7 @@ public class Path {
|
|||
valid = this.arcs.get(0).getOrigin().equals(this.origin);
|
||||
for (int i = 1; i < 3; i++) {
|
||||
if (this.arcs.size() > i)
|
||||
valid = valid && (this.arcs.get(i).getOrigin().equals(this.arcs.get(i - 1).getDestination()));
|
||||
valid = valid && (this.arcs.get(i).getOrigin().equals(this.arcs.get(i-1).getDestination()));
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
|
|
@ -249,8 +214,9 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Compute the length of this path (in meters).
|
||||
*
|
||||
*
|
||||
* @return Total length of the path (in meters).
|
||||
*
|
||||
*/
|
||||
public float getLength() {
|
||||
float length = 0;
|
||||
|
|
@ -262,10 +228,12 @@ public class Path {
|
|||
|
||||
/**
|
||||
* Compute the time required to travel this path if moving at the given speed.
|
||||
*
|
||||
*
|
||||
* @param speed Speed to compute the travel time.
|
||||
*
|
||||
* @return Time (in seconds) required to travel this path at the given speed (in
|
||||
* kilometers-per-hour).
|
||||
* kilometers-per-hour).
|
||||
*
|
||||
*/
|
||||
public double getTravelTime(double speed) {
|
||||
float time = 0;
|
||||
|
|
@ -278,8 +246,9 @@ public class Path {
|
|||
/**
|
||||
* Compute the time to travel this path if moving at the maximum allowed speed
|
||||
* on every arc.
|
||||
*
|
||||
*
|
||||
* @return Minimum travel time to travel this path (in seconds).
|
||||
*
|
||||
*/
|
||||
public double getMinimumTravelTime() {
|
||||
float time = 0;
|
||||
|
|
|
|||
Loading…
Reference in a new issue