diff --git a/be-graphes-algos/pom.xml b/be-graphes-algos/pom.xml index 42179f0..bfa028e 100644 --- a/be-graphes-algos/pom.xml +++ b/be-graphes-algos/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java index 2fb172d..3366bf9 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AbstractInputData.java @@ -74,7 +74,10 @@ public abstract class AbstractInputData { * {@link GraphStatistics#NO_MAXIMUM_SPEED} if none is set. */ public int getMaximumSpeed() { - return this.arcInspector.getMaximumSpeed(); + final int inspectorMaxSpeed = this.arcInspector.getMaximumSpeed(); + return inspectorMaxSpeed == GraphStatistics.NO_MAXIMUM_SPEED + ? getGraph().getGraphInformation().getMaximumSpeed() + : inspectorMaxSpeed; } /** diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java index 4dde531..9bb811f 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/AlgorithmFactory.java @@ -14,14 +14,14 @@ import org.insa.graphs.algorithm.shortestpath.ShortestPathAlgorithm; import org.insa.graphs.algorithm.weakconnectivity.WeaklyConnectedComponentsAlgorithm; /** - * Factory class used to register and retrieve algorithms based on their common - * ancestor and name. - * + * Factory class used to register and retrieve algorithms based on their common ancestor + * and name. */ public class AlgorithmFactory { // Map between algorithm names and class. - private final static Map>, Map>>> ALGORITHMS = new IdentityHashMap<>(); + private final static Map>, Map>>> ALGORITHMS = + new IdentityHashMap<>(); static { // Register weakly-connected components algorithm: @@ -29,8 +29,10 @@ public class AlgorithmFactory { WeaklyConnectedComponentsAlgorithm.class); // Register shortest path algorithm: - registerAlgorithm(ShortestPathAlgorithm.class, "Bellman-Ford", BellmanFordAlgorithm.class); - registerAlgorithm(ShortestPathAlgorithm.class, "Dijkstra", DijkstraAlgorithm.class); + registerAlgorithm(ShortestPathAlgorithm.class, "Bellman-Ford", + BellmanFordAlgorithm.class); + registerAlgorithm(ShortestPathAlgorithm.class, "Dijkstra", + DijkstraAlgorithm.class); registerAlgorithm(ShortestPathAlgorithm.class, "A*", AStarAlgorithm.class); // 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 - * the given base algorithm. - * + * Register the given algorithm class with the given name as a child class of the + * given base algorithm. + * * @param baseAlgorithm Base algorithm class that corresponds to the newly - * registered algorithm class (e.g., generic algorithm - * class for the problem). - * @param name Name for the registered algorithm class. - * @param algoClass Algorithm class to register. + * registered algorithm class (e.g., generic algorithm class for the + * problem). + * @param name Name for the registered algorithm class. + * @param algoClass Algorithm class to register. */ - public static void registerAlgorithm(Class> baseAlgorithm, - String name, Class> algoClass) { + public static void registerAlgorithm( + Class> baseAlgorithm, String name, + Class> algoClass) { if (!ALGORITHMS.containsKey(baseAlgorithm)) { 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. - * Assuming algorithm correspond to a class "Algorithm", this function returns - * an object equivalent to `new Algorithm(data)`. - * + * Assuming algorithm correspond to a class "Algorithm", this function returns an + * object equivalent to `new Algorithm(data)`. + * * @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. - * - * @throws Exception if something wrong happens when constructing the object, - * i.e. the given input data does not correspond to the given - * algorithm and/or no constructor that takes a single - * parameter of type (data.getClass()) exists. + * @throws Exception if something wrong happens when constructing the object, i.e. + * the given input data does not correspond to the given algorithm and/or no + * constructor that takes a single parameter of type (data.getClass()) + * exists. */ public static AbstractAlgorithm createAlgorithm( Class> algorithm, AbstractInputData data) @@ -79,11 +80,12 @@ public class AlgorithmFactory { // Within this set, find the constructor that can be called with "data" (only). AbstractAlgorithm constructed = null; - for (Constructor c: constructors) { + for (Constructor c : constructors) { Class[] params = c.getParameterTypes(); if (params.length == 1 && params[0].isAssignableFrom(data.getClass())) { c.setAccessible(true); - constructed = (AbstractAlgorithm) c.newInstance(new Object[] { data }); + constructed = + (AbstractAlgorithm) c.newInstance(new Object[] { data }); break; } } @@ -91,15 +93,12 @@ public class AlgorithmFactory { } /** - * Return the algorithm class corresponding to the given base algorithm class - * and name. The algorithm must have been previously registered using - * registerAlgorithm. - * + * Return the algorithm class corresponding to the given base algorithm class and + * name. The algorithm must have been previously registered using registerAlgorithm. + * * @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. - * * @see #registerAlgorithm */ public static Class> getAlgorithmClass( @@ -108,14 +107,12 @@ public class AlgorithmFactory { } /** - * Return the list of names corresponding to the registered algorithm classes - * for the given base algorithm class. - * + * Return the list of names corresponding to the registered algorithm classes for + * the given base algorithm class. + * * @param baseAlgorithm Base algorithm class for the algorithm class names to - * retrieve. - * + * retrieve. * @return Names of the currently registered algorithms. - * * @see #registerAlgorithm */ public static Set getAlgorithmNames( diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java index ff6d26e..b37571c 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspector.java @@ -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 - * costs of the usable arcs.. + * costs of the usable arcs. */ public interface ArcInspector { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java index d13caf6..45c1a75 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java @@ -1,6 +1,6 @@ package org.insa.graphs.algorithm; -import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import java.util.List; @@ -12,169 +12,113 @@ import org.insa.graphs.model.AccessRestrictions.AccessRestriction; 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. */ public static List getAllFilters() { - List 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() // to get an understandable output!): - - return filters; + return Arrays.asList(new NoFilterByLengthArcInspector(), + new OnlyCarsByLengthArcInspector(), new OnlyCarsByTimeArcInspector(), + new OnlyPedestrianByTime()); } } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java index bacb8e3..18a540f 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java @@ -8,9 +8,17 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { @Override protected ShortestPathSolution doRun() { + + // retrieve data from the input problem (getInputData() is inherited from the + // parent class ShortestPathAlgorithm) final ShortestPathData data = getInputData(); + + // variable that will contain the solution of the shortest path problem ShortestPathSolution solution = null; - // TODO: + + // TODO: implement the Dijkstra algorithm + + // when the algorithm terminates, return the solution that has been found return solution; } diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java index a0468fe..3ba4b86 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeapFormatter.java @@ -155,8 +155,8 @@ public class BinaryHeapFormatter { * Creates a multi-lines string representing a sorted view of the given binary heap. * * @param heap The binary heap to display. - * @param maxElement Maximum number of elements to display. or {@code -1} to display - * all the elements. + * @param max_elements Maximum number of elements to display. or {@code -1} to + * display all the elements. * @return a string containing a sorted view the given binary heap. */ public static > String toStringSorted(BinaryHeap heap, diff --git a/be-graphes-gui/pom.xml b/be-graphes-gui/pom.xml index 6a27386..860bc55 100644 --- a/be-graphes-gui/pom.xml +++ b/be-graphes-gui/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 org.insa.graphs @@ -64,13 +66,6 @@ ${mapsforge.version} - - - org.mapsforge - mapsforge-themes - ${mapsforge.version} - - org.mapsforge diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java index 333a20c..6b96f60 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java @@ -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 // destination, avoid drawing two-ways arc twice. if (arc.getRoadInformation().isOneWay() - || arc.getOrigin().compareTo(arc.getDestination()) < 0) { + || arc.getOrigin().getId() < arc.getDestination().getId()) { drawArc(arc, palette, false); } } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java index 7be58b3..aa7ea04 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/simple/Launch.java @@ -21,9 +21,8 @@ public class Launch { /** * Create a new Drawing inside a JFrame an return it. - * + * * @return The created drawing. - * * @throws Exception if something wrong happens when creating the graph. */ public static Drawing createDrawing() throws Exception { @@ -45,29 +44,36 @@ public class Launch { public static void main(String[] args) throws Exception { - // 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 pathName = "/home/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Paths/path_fr31insa_rangueil_r2.path"; + // visit these directory to see the list of available files on commetud. + final String mapName = + "/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 GraphReader reader = new BinaryGraphReader( - new DataInputStream(new BufferedInputStream(new FileInputStream(mapName)))); + final Graph graph; + final Path path; - // TODO: Read the graph. - final Graph graph = null; + // create a graph reader + 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(); - // TODO: Draw the graph on the drawing. + // TODO: draw the graph on the drawing - // TODO: Create a PathReader. - final PathReader pathReader = null; + // TODO: create a path reader + try (final PathReader pathReader = null) { - // TODO: Read the path. - final Path path = null; + // TODO: read the path + path = null; + } - // TODO: Draw the path. + // TODO: draw the path on the drawing } } diff --git a/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java b/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java index 34f0efb..e6544e6 100644 --- a/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java +++ b/be-graphes-gui/src/main/java/org/insa/graphs/gui/utils/FileUtils.java @@ -59,10 +59,10 @@ public class FileUtils { static { // Populate folderToEntry 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, 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, new PreferencesEntry("DefaultPathOutputsFolder", "paths")); diff --git a/be-graphes-model/pom.xml b/be-graphes-model/pom.xml index a63feff..f3cab76 100644 --- a/be-graphes-model/pom.xml +++ b/be-graphes-model/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java index 8539407..1655eab 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Node.java @@ -16,8 +16,7 @@ import java.util.List; * Nodes are comparable based on their ID. *

*/ -public final class Node implements Comparable { - +public final class Node { /** *

* Link the two given nodes with one or two arcs (depending on roadInformation), @@ -38,13 +37,13 @@ public final class Node implements Comparable { */ public static Arc linkNodes(Node origin, Node destination, float length, RoadInformation roadInformation, ArrayList 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 { 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()); - } - } diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java index 6ebdb73..7580981 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java @@ -8,28 +8,23 @@ import java.util.List; *

* Class representing a path between nodes in a graph. *

- * *

- * 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. *

- * */ 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 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 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 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 nodes 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: *
    *
  • it is empty;
  • *
  • it contains a single node (without arcs);
  • - *
  • 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.
  • + *
  • 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.
  • *
- * + * * @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() { diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java index 13302dd..fb438df 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Point.java @@ -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. diff --git a/eclipse-java-google-style.xml b/eclipse-java-google-style.xml index 840826c..05f42b6 100644 --- a/eclipse-java-google-style.xml +++ b/eclipse-java-google-style.xml @@ -88,6 +88,8 @@ + > + > @@ -167,7 +169,7 @@ - + diff --git a/pom.xml b/pom.xml index bcd9806..c49402a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.insa.graphs @@ -10,7 +11,7 @@ be-graphes-all - 1.8 + 17 ${jdk.version} ${jdk.version} UTF-8 @@ -18,6 +19,7 @@ + maven-compiler-plugin 3.1 @@ -26,6 +28,23 @@ ${jdk.version} + + + net.revelc.code.formatter + formatter-maven-plugin + 2.24.1 + + + ${project.basedir}/../eclipse-java-google-style.xml + + + + + format + + + +