[dev] Fetch changes from public folder.

This commit is contained in:
Mikael CAPELLE
2024-11-21 10:08:08 +01:00
parent b8c86f3645
commit 443539a6ba
17 changed files with 257 additions and 299 deletions

View File

@@ -16,8 +16,7 @@ import java.util.List;
* Nodes are comparable based on their ID.
* </p>
*/
public final class Node implements Comparable<Node> {
public final class Node {
/**
* <p>
* Link the two given nodes with one or two arcs (depending on roadInformation),
@@ -38,13 +37,13 @@ public final class Node implements Comparable<Node> {
*/
public static Arc linkNodes(Node origin, Node destination, float length,
RoadInformation roadInformation, ArrayList<Point> points) {
final Arc arc;
Arc arc = null;
if (roadInformation.isOneWay()) {
arc = new ArcForward(origin, destination, length, roadInformation, points);
origin.addSuccessor(arc);
}
else {
final Arc d2o;
Arc d2o;
if (origin.getId() < destination.getId()) {
arc = new ArcForward(origin, destination, length, roadInformation,
points);
@@ -140,15 +139,4 @@ public final class Node implements Comparable<Node> {
return false;
}
/**
* Compare the ID of this node with the ID of the given node.
*
* @param other Node to compare this node with.
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Node other) {
return Integer.compare(getId(), other.getId());
}
}

View File

@@ -8,28 +8,23 @@ 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.
* 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.
*
* 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.
*
* @deprecated Need to be implemented.
*/
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
@@ -40,17 +35,14 @@ public class Path {
}
/**
* Create a new path that goes through the given list of nodes (in order),
* choosing the shortest route if multiple are available.
*
* 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.
*
* @deprecated Need to be implemented.
*/
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
@@ -62,18 +54,16 @@ public class Path {
/**
* 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).
* @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).
*/
public static Path concatenate(Path... paths) throws IllegalArgumentException {
if (paths.length == 0) {
throw new IllegalArgumentException("Cannot concatenate an empty list of paths.");
throw new IllegalArgumentException(
"Cannot concatenate an empty list of paths.");
}
final String mapId = paths[0].getGraph().getMapId();
for (int i = 1; i < paths.length; ++i) {
@@ -83,7 +73,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);
@@ -105,7 +95,7 @@ public class Path {
/**
* Create an empty path corresponding to the given graph.
*
*
* @param graph Graph containing the path.
*/
public Path(Graph graph) {
@@ -116,7 +106,7 @@ public class Path {
/**
* Create a new path containing a single node.
*
*
* @param graph Graph containing the path.
* @param node Single node of the path.
*/
@@ -128,7 +118,7 @@ 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.
*/
@@ -168,7 +158,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() {
@@ -177,7 +167,7 @@ public class Path {
/**
* Get the number of <b>nodes</b> in this path.
*
*
* @return Number of nodes in this path.
*/
public int size() {
@@ -185,19 +175,15 @@ public class Path {
}
/**
* Check if this path is valid.
*
* A path is valid if any of the following is true:
* Check if this path is valid. A path is valid if any of the following is true:
* <ul>
* <li>it is empty;</li>
* <li>it contains a single node (without arcs);</li>
* <li>the first arc has for origin the origin of the path and, for two
* consecutive arcs, the destination of the first one is the origin of the
* second one.</li>
* <li>the first arc has for origin the origin of the path and, for two 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() {
@@ -207,9 +193,8 @@ public class Path {
/**
* Compute the length of this path (in meters).
*
*
* @return Total length of the path (in meters).
*
* @deprecated Need to be implemented.
*/
public float getLength() {
@@ -219,12 +204,10 @@ 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).
*
* @deprecated Need to be implemented.
*/
public double getTravelTime(double speed) {
@@ -233,11 +216,10 @@ public class Path {
}
/**
* Compute the time to travel this path if moving at the maximum allowed speed
* on every arc.
*
* 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).
*
* @deprecated Need to be implemented.
*/
public double getMinimumTravelTime() {

View File

@@ -24,7 +24,17 @@ public final class Point {
* Math.cos(Math.toRadians(p2.getLatitude()));
double cosLong =
Math.cos(Math.toRadians(p2.getLongitude() - p1.getLongitude()));
return EARTH_RADIUS * Math.acos(sinLat + cosLat * cosLong);
double koef = sinLat + cosLat * cosLong;
if (koef >= 1.0) {
koef = 1.0;
}
if (koef <= -1.0) {
koef = -1.0;
}
return (EARTH_RADIUS * Math.acos(koef));
}
// Longitude and latitude of the point.