[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

@ -1,5 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -74,7 +74,10 @@ public abstract class AbstractInputData {
* {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is set. * {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is set.
*/ */
public int getMaximumSpeed() { public int getMaximumSpeed() {
return this.arcInspector.getMaximumSpeed(); final int inspectorMaxSpeed = this.arcInspector.getMaximumSpeed();
return inspectorMaxSpeed == GraphStatistics.NO_MAXIMUM_SPEED
? getGraph().getGraphInformation().getMaximumSpeed()
: inspectorMaxSpeed;
} }
/** /**

View File

@ -14,14 +14,14 @@ import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm;
import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm; import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm;
/** /**
* Factory class used to register and retrieve algorithms based on their common * Factory class used to register and retrieve algorithms based on their common ancestor
* ancestor and name. * and name.
*
*/ */
public class AlgorithmFactory { public class AlgorithmFactory {
// Map between algorithm names and class. // Map between algorithm names and class.
private final static Map<Class<? extends AbstractAlgorithm<?>>, Map<String, Class<? extends AbstractAlgorithm<?>>>> ALGORITHMS = new IdentityHashMap<>(); private final static Map<Class<? extends AbstractAlgorithm<?>>, Map<String, Class<? extends AbstractAlgorithm<?>>>> ALGORITHMS =
new IdentityHashMap<>();
static { static {
// Register weakly-connected components algorithm: // Register weakly-connected components algorithm:
@ -29,8 +29,10 @@ public class AlgorithmFactory {
WeaklyConnectedComponentsAlgorithm.class); WeaklyConnectedComponentsAlgorithm.class);
// Register shortest path algorithm: // Register shortest path algorithm:
registerAlgorithm(ShortestPathAlgorithm.class, "Bellman-Ford", BellmanFordAlgorithm.class); registerAlgorithm(ShortestPathAlgorithm.class, "Bellman-Ford",
registerAlgorithm(ShortestPathAlgorithm.class, "Dijkstra", DijkstraAlgorithm.class); BellmanFordAlgorithm.class);
registerAlgorithm(ShortestPathAlgorithm.class, "Dijkstra",
DijkstraAlgorithm.class);
registerAlgorithm(ShortestPathAlgorithm.class, "A*", AStarAlgorithm.class); registerAlgorithm(ShortestPathAlgorithm.class, "A*", AStarAlgorithm.class);
// Register your algorithms here: // Register your algorithms here:
@ -39,17 +41,18 @@ public class AlgorithmFactory {
} }
/** /**
* Register the given algorithm class with the given name as a child class of * Register the given algorithm class with the given name as a child class of the
* the given base algorithm. * given base algorithm.
* *
* @param baseAlgorithm Base algorithm class that corresponds to the newly * @param baseAlgorithm Base algorithm class that corresponds to the newly
* registered algorithm class (e.g., generic algorithm * registered algorithm class (e.g., generic algorithm class for the
* class for the problem). * problem).
* @param name Name for the registered algorithm class. * @param name Name for the registered algorithm class.
* @param algoClass Algorithm class to register. * @param algoClass Algorithm class to register.
*/ */
public static void registerAlgorithm(Class<? extends AbstractAlgorithm<?>> baseAlgorithm, public static void registerAlgorithm(
String name, Class<? extends AbstractAlgorithm<?>> algoClass) { Class<? extends AbstractAlgorithm<?>> baseAlgorithm, String name,
Class<? extends AbstractAlgorithm<?>> algoClass) {
if (!ALGORITHMS.containsKey(baseAlgorithm)) { if (!ALGORITHMS.containsKey(baseAlgorithm)) {
ALGORITHMS.put(baseAlgorithm, new LinkedHashMap<>()); ALGORITHMS.put(baseAlgorithm, new LinkedHashMap<>());
} }
@ -58,18 +61,16 @@ public class AlgorithmFactory {
/** /**
* Create an instance of the given algorithm class using the given input data. * Create an instance of the given algorithm class using the given input data.
* Assuming algorithm correspond to a class "Algorithm", this function returns * Assuming algorithm correspond to a class "Algorithm", this function returns an
* an object equivalent to `new Algorithm(data)`. * object equivalent to `new Algorithm(data)`.
* *
* @param algorithm Class of the algorithm to create. * @param algorithm Class of the algorithm to create.
* @param data Input data for the algorithm. * @param data Input data for the algorithm.
*
* @return A new instance of the given algorithm class using the given data. * @return A new instance of the given algorithm class using the given data.
* * @throws Exception if something wrong happens when constructing the object, i.e.
* @throws Exception if something wrong happens when constructing the object, * the given input data does not correspond to the given algorithm and/or no
* i.e. the given input data does not correspond to the given * constructor that takes a single parameter of type (data.getClass())
* algorithm and/or no constructor that takes a single * exists.
* parameter of type (data.getClass()) exists.
*/ */
public static AbstractAlgorithm<?> createAlgorithm( public static AbstractAlgorithm<?> createAlgorithm(
Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data) Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data)
@ -79,11 +80,12 @@ public class AlgorithmFactory {
// Within this set, find the constructor that can be called with "data" (only). // Within this set, find the constructor that can be called with "data" (only).
AbstractAlgorithm<?> constructed = null; AbstractAlgorithm<?> constructed = null;
for (Constructor<?> c: constructors) { for (Constructor<?> c : constructors) {
Class<?>[] params = c.getParameterTypes(); Class<?>[] params = c.getParameterTypes();
if (params.length == 1 && params[0].isAssignableFrom(data.getClass())) { if (params.length == 1 && params[0].isAssignableFrom(data.getClass())) {
c.setAccessible(true); c.setAccessible(true);
constructed = (AbstractAlgorithm<?>) c.newInstance(new Object[] { data }); constructed =
(AbstractAlgorithm<?>) c.newInstance(new Object[] { data });
break; break;
} }
} }
@ -91,15 +93,12 @@ public class AlgorithmFactory {
} }
/** /**
* Return the algorithm class corresponding to the given base algorithm class * Return the algorithm class corresponding to the given base algorithm class and
* and name. The algorithm must have been previously registered using * name. The algorithm must have been previously registered using registerAlgorithm.
* registerAlgorithm.
* *
* @param baseAlgorithm Base algorithm class for the algorithm to retrieve. * @param baseAlgorithm Base algorithm class for the algorithm to retrieve.
* @param name Name of the algorithm to retrieve. * @param name Name of the algorithm to retrieve.
*
* @return Class corresponding to the given name. * @return Class corresponding to the given name.
*
* @see #registerAlgorithm * @see #registerAlgorithm
*/ */
public static Class<? extends AbstractAlgorithm<?>> getAlgorithmClass( public static Class<? extends AbstractAlgorithm<?>> getAlgorithmClass(
@ -108,14 +107,12 @@ public class AlgorithmFactory {
} }
/** /**
* Return the list of names corresponding to the registered algorithm classes * Return the list of names corresponding to the registered algorithm classes for
* for the given base algorithm class. * the given base algorithm class.
* *
* @param baseAlgorithm Base algorithm class for the algorithm class names to * @param baseAlgorithm Base algorithm class for the algorithm class names to
* retrieve. * retrieve.
*
* @return Names of the currently registered algorithms. * @return Names of the currently registered algorithms.
*
* @see #registerAlgorithm * @see #registerAlgorithm
*/ */
public static Set<String> getAlgorithmNames( public static Set<String> getAlgorithmNames(

View File

@ -6,7 +6,7 @@ import org.insa.graphs.model.GraphStatistics;
/** /**
* This class can be used to indicate to an algorithm which arcs can be used and the * This class can be used to indicate to an algorithm which arcs can be used and the
* costs of the usable arcs.. * costs of the usable arcs.
*/ */
public interface ArcInspector { public interface ArcInspector {

View File

@ -1,6 +1,6 @@
package org.insa.graphs.algorithm; package org.insa.graphs.algorithm;
import java.util.ArrayList; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
@ -12,169 +12,113 @@ import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
public class ArcInspectorFactory { public class ArcInspectorFactory {
private static class NoFilterByLengthArcInspector implements ArcInspector {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, all roads allowed";
}
};
private static class OnlyCarsByLengthArcInspector
extends NoFilterByLengthArcInspector {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.MOTORCAR,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public String toString() {
return "Shortest path, only roads open for cars";
}
};
private static class OnlyCarsByTimeArcInspector
extends NoFilterByLengthArcInspector {
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime();
}
@Override
public Mode getMode() {
return Mode.TIME;
}
@Override
public String toString() {
return "Fastest path, all roads allowed";
}
};
private static class OnlyPedestrianByTime implements ArcInspector {
static final int maxPedestrianSpeed = 5;
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.FOOT,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getTravelTime(Math.min(maxPedestrianSpeed,
arc.getRoadInformation().getMaximumSpeed()));
}
@Override
public String toString() {
return "Fastest path for pedestrian";
}
@Override
public int getMaximumSpeed() {
return 5;
}
@Override
public Mode getMode() {
return Mode.TIME;
}
};
/** /**
* @return List of all arc filters in this factory. * @return List of all arc filters in this factory.
*/ */
public static List<ArcInspector> getAllFilters() { public static List<ArcInspector> getAllFilters() {
List<ArcInspector> filters = new ArrayList<>();
// Common filters:
// No filter (all arcs allowed):
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, all roads allowed";
}
});
// Only road allowed for cars and length:
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.MOTORCAR,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, only roads open for cars";
}
});
// Only road allowed for cars and time:
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime();
}
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
@Override
public Mode getMode() {
return Mode.TIME;
}
@Override
public String toString() {
return "Fastest path, all roads allowed";
}
});
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.MOTORCAR,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime();
}
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
@Override
public Mode getMode() {
return Mode.TIME;
}
@Override
public String toString() {
return "Fastest path, only roads open for cars";
}
});
// Non-private roads for pedestrian and bicycle:
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(
AccessMode.FOOT,
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN,
AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getTravelTime(Math.min(getMaximumSpeed(),
arc.getRoadInformation().getMaximumSpeed()));
}
@Override
public String toString() {
return "Fastest path for pedestrian";
}
@Override
public int getMaximumSpeed() {
return 5;
}
@Override
public Mode getMode() {
return Mode.TIME;
}
});
// Add your own filters here (do not forget to implement toString() // Add your own filters here (do not forget to implement toString()
// to get an understandable output!): // to get an understandable output!):
return Arrays.asList(new NoFilterByLengthArcInspector(),
return filters; new OnlyCarsByLengthArcInspector(), new OnlyCarsByTimeArcInspector(),
new OnlyPedestrianByTime());
} }
} }

View File

@ -8,9 +8,17 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
@Override @Override
protected ShortestPathSolution doRun() { protected ShortestPathSolution doRun() {
// retrieve data from the input problem (getInputData() is inherited from the
// parent class ShortestPathAlgorithm)
final ShortestPathData data = getInputData(); final ShortestPathData data = getInputData();
// variable that will contain the solution of the shortest path problem
ShortestPathSolution solution = null; ShortestPathSolution solution = null;
// TODO:
// TODO: implement the Dijkstra algorithm
// when the algorithm terminates, return the solution that has been found
return solution; return solution;
} }

View File

@ -155,8 +155,8 @@ public class BinaryHeapFormatter {
* Creates a multi-lines string representing a sorted view of the given binary heap. * Creates a multi-lines string representing a sorted view of the given binary heap.
* *
* @param heap The binary heap to display. * @param heap The binary heap to display.
* @param maxElement Maximum number of elements to display. or {@code -1} to display * @param max_elements Maximum number of elements to display. or {@code -1} to
* all the elements. * display all the elements.
* @return a string containing a sorted view the given binary heap. * @return a string containing a sorted view the given binary heap.
*/ */
public static <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap, public static <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap,

View File

@ -1,5 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.insa.graphs</groupId> <groupId>org.insa.graphs</groupId>
@ -64,13 +66,6 @@
<version>${mapsforge.version}</version> <version>${mapsforge.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
<dependency>
<groupId>org.mapsforge</groupId>
<artifactId>mapsforge-themes</artifactId>
<version>${mapsforge.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader --> <!-- https://mvnrepository.com/artifact/org.mapsforge/mapsforge-map-reader -->
<dependency> <dependency>
<groupId>org.mapsforge</groupId> <groupId>org.mapsforge</groupId>

View File

@ -686,7 +686,7 @@ public class BasicDrawing extends JPanel implements Drawing {
// Draw arcs only if there are one-way arcs or if origin is lower than // Draw arcs only if there are one-way arcs or if origin is lower than
// destination, avoid drawing two-ways arc twice. // destination, avoid drawing two-ways arc twice.
if (arc.getRoadInformation().isOneWay() if (arc.getRoadInformation().isOneWay()
|| arc.getOrigin().compareTo(arc.getDestination()) < 0) { || arc.getOrigin().getId() < arc.getDestination().getId()) {
drawArc(arc, palette, false); drawArc(arc, palette, false);
} }
} }

View File

@ -23,7 +23,6 @@ public class Launch {
* Create a new Drawing inside a JFrame an return it. * Create a new Drawing inside a JFrame an return it.
* *
* @return The created drawing. * @return The created drawing.
*
* @throws Exception if something wrong happens when creating the graph. * @throws Exception if something wrong happens when creating the graph.
*/ */
public static Drawing createDrawing() throws Exception { public static Drawing createDrawing() throws Exception {
@ -45,29 +44,36 @@ public class Launch {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// Visit these directory to see the list of available files on Commetud. // visit these directory to see the list of available files on commetud.
final String mapName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr"; final String mapName =
final String pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path"; "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/insa.mapgr";
final String pathName =
"/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path";
// Create a graph reader. final Graph graph;
final GraphReader reader = new BinaryGraphReader( final Path path;
new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
// TODO: Read the graph. // create a graph reader
final Graph graph = null; try (final GraphReader reader = new BinaryGraphReader(new DataInputStream(
new BufferedInputStream(new FileInputStream(mapName))))) {
// Create the drawing: // TODO: read the graph
graph = null;
}
// 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
// TODO: Create a PathReader. // TODO: create a path reader
final PathReader pathReader = null; try (final PathReader pathReader = null) {
// TODO: Read the path. // TODO: read the path
final Path path = null; path = null;
}
// TODO: Draw the path. // TODO: draw the path on the drawing
} }
} }

View File

@ -59,10 +59,10 @@ public class FileUtils {
static { static {
// Populate folderToEntry // Populate folderToEntry
folderToEntry.put(FolderType.Map, new PreferencesEntry("DefaultMapFolder", folderToEntry.put(FolderType.Map, new PreferencesEntry("DefaultMapFolder",
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps")); "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps"));
folderToEntry.put(FolderType.PathInput, folderToEntry.put(FolderType.PathInput,
new PreferencesEntry("DefaultPathInputFolder", new PreferencesEntry("DefaultPathInputFolder",
"/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths")); "/mnt/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths"));
folderToEntry.put(FolderType.PathOutput, folderToEntry.put(FolderType.PathOutput,
new PreferencesEntry("DefaultPathOutputsFolder", "paths")); new PreferencesEntry("DefaultPathOutputsFolder", "paths"));

View File

@ -1,5 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>

View File

@ -16,8 +16,7 @@ import java.util.List;
* Nodes are comparable based on their ID. * Nodes are comparable based on their ID.
* </p> * </p>
*/ */
public final class Node implements Comparable<Node> { public final class Node {
/** /**
* <p> * <p>
* Link the two given nodes with one or two arcs (depending on roadInformation), * 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, public static Arc linkNodes(Node origin, Node destination, float length,
RoadInformation roadInformation, ArrayList<Point> points) { RoadInformation roadInformation, ArrayList<Point> points) {
final Arc arc; Arc arc = null;
if (roadInformation.isOneWay()) { if (roadInformation.isOneWay()) {
arc = new ArcForward(origin, destination, length, roadInformation, points); arc = new ArcForward(origin, destination, length, roadInformation, points);
origin.addSuccessor(arc); origin.addSuccessor(arc);
} }
else { else {
final Arc d2o; Arc d2o;
if (origin.getId() < destination.getId()) { if (origin.getId() < destination.getId()) {
arc = new ArcForward(origin, destination, length, roadInformation, arc = new ArcForward(origin, destination, length, roadInformation,
points); points);
@ -140,15 +139,4 @@ public final class Node implements Comparable<Node> {
return false; 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> * <p>
* Class representing a path between nodes in a graph. * Class representing a path between nodes in a graph.
* </p> * </p>
*
* <p> * <p>
* A path is represented as a list of {@link Arc} with an origin and not a list * A path is represented as a list of {@link Arc} with an origin and not a list of
* of {@link Node} due to the multi-graph nature (multiple arcs between two * {@link Node} due to the multi-graph nature (multiple arcs between two nodes) of the
* nodes) of the considered graphs. * considered graphs.
* </p> * </p>
*
*/ */
public class Path { public class Path {
/** /**
* Create a new path that goes through the given list of nodes (in order), * Create a new path that goes through the given list of nodes (in order), choosing
* choosing the fastest route if multiple are available. * the fastest route if multiple are available.
* *
* @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. * @deprecated Need to be implemented.
*/ */
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes) 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), * Create a new path that goes through the given list of nodes (in order), choosing
* choosing the shortest route if multiple are available. * the shortest route if multiple are available.
* *
* @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. * @deprecated Need to be implemented.
*/ */
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes) public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
@ -64,16 +56,14 @@ public class Path {
* 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 map
* @throws IllegalArgumentException if the paths cannot be concatenated (IDs of * 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 { public static Path concatenate(Path... paths) throws IllegalArgumentException {
if (paths.length == 0) { 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(); final String mapId = paths[0].getGraph().getMapId();
for (int i = 1; i < paths.length; ++i) { for (int i = 1; i < paths.length; ++i) {
@ -83,7 +73,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);
@ -185,19 +175,15 @@ public class Path {
} }
/** /**
* Check if this path is valid. * Check if this path is valid. 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>
* <li>it contains a single node (without arcs);</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 * <li>the first arc has for origin the origin of the path and, for two consecutive
* consecutive arcs, the destination of the first one is the origin of the * arcs, the destination of the first one is the origin of the second one.</li>
* second one.</li>
* </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. * @deprecated Need to be implemented.
*/ */
public boolean isValid() { public boolean isValid() {
@ -209,7 +195,6 @@ 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).
*
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public float getLength() { public float getLength() {
@ -221,10 +206,8 @@ 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).
*
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public double getTravelTime(double speed) { 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 * Compute the time to travel this path if moving at the maximum allowed speed on
* on every arc. * every arc.
* *
* @return Minimum travel time to travel this path (in seconds). * @return Minimum travel time to travel this path (in seconds).
*
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public double getMinimumTravelTime() { public double getMinimumTravelTime() {

View File

@ -24,7 +24,17 @@ public final class Point {
* Math.cos(Math.toRadians(p2.getLatitude())); * Math.cos(Math.toRadians(p2.getLatitude()));
double cosLong = double cosLong =
Math.cos(Math.toRadians(p2.getLongitude() - p1.getLongitude())); 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. // Longitude and latitude of the point.

View File

@ -88,6 +88,8 @@
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false" /> <setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="88" /> <setting id="org.eclipse.jdt.core.formatter.lineSplit" value="88" />
>
>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation.count_dependent" value="16|4|48" /> <setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation.count_dependent" value="16|4|48" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert" />
@ -167,7 +169,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="2" /> <setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert" />
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert" /> <setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert" />

23
pom.xml
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.insa.graphs</groupId> <groupId>org.insa.graphs</groupId>
@ -10,7 +11,7 @@
<name>be-graphes-all</name> <name>be-graphes-all</name>
<properties> <properties>
<jdk.version>1.8</jdk.version> <jdk.version>17</jdk.version>
<maven.compiler.source>${jdk.version}</maven.compiler.source> <maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target> <maven.compiler.target>${jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -18,6 +19,7 @@
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <version>3.1</version>
@ -26,6 +28,23 @@
<target>${jdk.version}</target> <target>${jdk.version}</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.24.1</version>
<configuration>
<configFile>
${project.basedir}/../eclipse-java-google-style.xml</configFile>
</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>