[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"?>
<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>
<parent>

View File

@ -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;
}
/**

View File

@ -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<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 {
// 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<? extends AbstractAlgorithm<?>> baseAlgorithm,
String name, Class<? extends AbstractAlgorithm<?>> algoClass) {
public static void registerAlgorithm(
Class<? extends AbstractAlgorithm<?>> baseAlgorithm, String name,
Class<? extends AbstractAlgorithm<?>> 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<? 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).
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<? extends AbstractAlgorithm<?>> 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<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
* costs of the usable arcs..
* costs of the usable arcs.
*/
public interface ArcInspector {

View File

@ -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<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()
// to get an understandable output!):
return filters;
return Arrays.asList(new NoFilterByLengthArcInspector(),
new OnlyCarsByLengthArcInspector(), new OnlyCarsByTimeArcInspector(),
new OnlyPedestrianByTime());
}
}

View File

@ -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;
}

View File

@ -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 <E extends Comparable<E>> String toStringSorted(BinaryHeap<E> heap,

View File

@ -1,5 +1,7 @@
<?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>
<parent>
<groupId>org.insa.graphs</groupId>
@ -64,13 +66,6 @@
<version>${mapsforge.version}</version>
</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 -->
<dependency>
<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
// 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);
}
}

View File

@ -23,7 +23,6 @@ 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
}
}

View File

@ -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"));

View File

@ -1,5 +1,7 @@
<?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>
<parent>

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)
@ -64,16 +56,14 @@ 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);
@ -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() {
@ -209,7 +195,6 @@ 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() {
@ -221,10 +206,8 @@ 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.

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.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.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.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_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.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_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" />

23
pom.xml
View File

@ -1,5 +1,6 @@
<?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>
<groupId>org.insa.graphs</groupId>
@ -10,7 +11,7 @@
<name>be-graphes-all</name>
<properties>
<jdk.version>1.8</jdk.version>
<jdk.version>17</jdk.version>
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -18,6 +19,7 @@
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
@ -26,6 +28,23 @@
<target>${jdk.version}</target>
</configuration>
</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>
</build>