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.GraphReader;
|
||||||
import org.insa.graphs.model.io.MapMismatchException;
|
import org.insa.graphs.model.io.MapMismatchException;
|
||||||
|
|
||||||
|
|
||||||
public class MainWindow extends JFrame {
|
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();
|
JTextArea infoPanel = new JTextArea();
|
||||||
infoPanel.setMinimumSize(new Dimension(200, 50));
|
infoPanel.setMinimumSize(new Dimension(200, 50));
|
||||||
// infoPanel.setBackground(Color.WHITE);
|
infoPanel.setBackground(Color.WHITE);
|
||||||
infoPanel.setLineWrap(true);
|
infoPanel.setLineWrap(true);
|
||||||
infoPanel.setEditable(false);
|
infoPanel.setEditable(false);
|
||||||
this.logStream = new StreamCapturer(infoPanel);
|
this.logStream = new StreamCapturer(infoPanel);
|
||||||
|
|
@ -378,7 +377,7 @@ public class MainWindow extends JFrame {
|
||||||
mainPanel.setResizeWeight(0.8);
|
mainPanel.setResizeWeight(0.8);
|
||||||
mainPanel.setDividerSize(5);
|
mainPanel.setDividerSize(5);
|
||||||
|
|
||||||
// mainPanel.setBackground(Color.WHITE);
|
mainPanel.setBackground(Color.WHITE);
|
||||||
mainPanel.setLeftComponent(openPanel);
|
mainPanel.setLeftComponent(openPanel);
|
||||||
mainPanel.setRightComponent(rightComponent);
|
mainPanel.setRightComponent(rightComponent);
|
||||||
this.add(mainPanel, BorderLayout.CENTER);
|
this.add(mainPanel, BorderLayout.CENTER);
|
||||||
|
|
@ -845,16 +844,7 @@ public class MainWindow extends JFrame {
|
||||||
|
|
||||||
// Try to set system look and feel.
|
// Try to set system look and feel.
|
||||||
try {
|
try {
|
||||||
boolean isThemeSet = false;
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
* of {@link Node} due to the multi-graph nature (multiple arcs between two
|
* of {@link Node} due to the multi-graph nature (multiple arcs between two
|
||||||
* nodes) of the considered graphs.
|
* nodes) of the considered graphs.
|
||||||
* </p>
|
* </p>
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class Path {
|
public class Path {
|
||||||
|
|
||||||
|
|
@ -23,13 +24,19 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @param graph Graph containing the nodes in the list.
|
* @param graph Graph containing the nodes in the list.
|
||||||
* @param nodes List of nodes to build the path.
|
* @param nodes List of nodes to build the 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 {
|
||||||
return Path.createSmallestPath(graph, nodes, false);
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
|
// TODO:
|
||||||
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,75 +45,31 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @param graph Graph containing the nodes in the list.
|
* @param graph Graph containing the nodes in the list.
|
||||||
* @param nodes List of nodes to build the path.
|
* @param nodes List of nodes to build the 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 createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
return Path.createSmallestPath(graph, nodes, true);
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
}
|
// TODO:
|
||||||
|
|
||||||
/**
|
|
||||||
* 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));
|
|
||||||
return new Path(graph, arcs);
|
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.
|
* Concatenate the given paths.
|
||||||
*
|
*
|
||||||
* @param paths Array of paths to concatenate.
|
* @param paths Array of paths to concatenate.
|
||||||
|
*
|
||||||
* @return Concatenated path.
|
* @return Concatenated path.
|
||||||
|
*
|
||||||
* @throws IllegalArgumentException if the paths cannot be concatenated (IDs of
|
* @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
|
* map do not match, or the end of a path is not the beginning of the
|
||||||
* next).
|
* next).
|
||||||
*/
|
*/
|
||||||
public static Path concatenate(Path... paths) throws IllegalArgumentException {
|
public static Path concatenate(Path... paths) throws IllegalArgumentException {
|
||||||
if (paths.length == 0) {
|
if (paths.length == 0) {
|
||||||
|
|
@ -120,7 +83,7 @@ public class Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<Arc> arcs = new ArrayList<>();
|
ArrayList<Arc> arcs = new ArrayList<>();
|
||||||
for (Path path : paths) {
|
for (Path path: paths) {
|
||||||
arcs.addAll(path.getArcs());
|
arcs.addAll(path.getArcs());
|
||||||
}
|
}
|
||||||
Path path = new Path(paths[0].getGraph(), arcs);
|
Path path = new Path(paths[0].getGraph(), arcs);
|
||||||
|
|
@ -155,7 +118,7 @@ public class Path {
|
||||||
* Create a new path containing a single node.
|
* Create a new path containing a single node.
|
||||||
*
|
*
|
||||||
* @param graph Graph containing the path.
|
* @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) {
|
public Path(Graph graph, Node node) {
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
|
@ -167,7 +130,7 @@ public class Path {
|
||||||
* Create a new path with the given list of arcs.
|
* Create a new path with the given list of arcs.
|
||||||
*
|
*
|
||||||
* @param graph Graph containing the path.
|
* @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) {
|
public Path(Graph graph, List<Arc> arcs) {
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
|
|
@ -223,7 +186,7 @@ public class Path {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this path is valid.
|
* Check if this path is valid.
|
||||||
* <p>
|
*
|
||||||
* A path is valid if any of the following is true:
|
* A path is valid if any of the following is true:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>it is empty;</li>
|
* <li>it is empty;</li>
|
||||||
|
|
@ -234,6 +197,8 @@ 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() {
|
||||||
boolean valid = isEmpty() || (this.arcs.size() == 0 && this.origin != null);
|
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);
|
valid = this.arcs.get(0).getOrigin().equals(this.origin);
|
||||||
for (int i = 1; i < 3; i++) {
|
for (int i = 1; i < 3; i++) {
|
||||||
if (this.arcs.size() > 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;
|
return valid;
|
||||||
|
|
@ -251,6 +216,7 @@ public class Path {
|
||||||
* Compute the length of this path (in meters).
|
* Compute the length of this path (in meters).
|
||||||
*
|
*
|
||||||
* @return Total length of the path (in meters).
|
* @return Total length of the path (in meters).
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public float getLength() {
|
public float getLength() {
|
||||||
float length = 0;
|
float length = 0;
|
||||||
|
|
@ -264,8 +230,10 @@ public class Path {
|
||||||
* Compute the time required to travel this path if moving at the given speed.
|
* Compute the time required to travel this path if moving at the given speed.
|
||||||
*
|
*
|
||||||
* @param speed Speed to compute the travel time.
|
* @param speed Speed to compute the travel time.
|
||||||
|
*
|
||||||
* @return Time (in seconds) required to travel this path at the given speed (in
|
* @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) {
|
public double getTravelTime(double speed) {
|
||||||
float time = 0;
|
float time = 0;
|
||||||
|
|
@ -280,6 +248,7 @@ public class Path {
|
||||||
* on every arc.
|
* on every arc.
|
||||||
*
|
*
|
||||||
* @return Minimum travel time to travel this path (in seconds).
|
* @return Minimum travel time to travel this path (in seconds).
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public double getMinimumTravelTime() {
|
public double getMinimumTravelTime() {
|
||||||
float time = 0;
|
float time = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue