-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
1,952 additions
and
367 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
de.zabuza.maglev/src/de/zabuza/maglev/external/algorithms/DijkstraModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package de.zabuza.maglev.external.algorithms; | ||
|
||
import de.zabuza.maglev.external.graph.Edge; | ||
|
||
import java.util.OptionalDouble; | ||
|
||
/** | ||
* Interface for Dijkstra modules used by a {@code ModuleDijkstra}. Defines various methods that allow to manipulate how | ||
* the base Dijkstra works, like providing edge costs different to {@link Edge#getCost()}. | ||
* | ||
* @param <N> Type of the nodes | ||
* @param <E> Type of the edges | ||
* | ||
* @author Daniel Tischner {@literal <[email protected]>} | ||
*/ | ||
public interface DijkstraModule<N, E extends Edge<N>> { | ||
/** | ||
* Whether or not the given edge should be considered for relaxation. The algorithm will ignore the edge and not | ||
* follow it if this method returns {@code false}. | ||
* | ||
* @param edge The edge in question | ||
* @param pathDestination The destination of the shortest path computation or {@code null} if not present | ||
* | ||
* @return {@code True} if the edge should be considered, {@code false} otherwise | ||
*/ | ||
@SuppressWarnings({ "SameReturnValue", "MethodReturnAlwaysConstant", "BooleanMethodNameMustStartWithQuestion" }) | ||
default boolean doConsiderEdgeForRelaxation(@SuppressWarnings("unused") final E edge, | ||
@SuppressWarnings("unused") final N pathDestination) { | ||
return true; | ||
} | ||
|
||
/** | ||
* Gets an estimate about the shortest path distance from the given node to the destination of the shortest path | ||
* computation.<br> | ||
* <br> | ||
* The estimate must be <i>monotone</i> and <i>admissible</i>. | ||
* | ||
* @param node The node to estimate the distance from | ||
* @param pathDestination The destination to estimate the distance to | ||
* | ||
* @return An estimate about the shortest path distance or empty if the module has no estimate | ||
*/ | ||
default OptionalDouble getEstimatedDistance(@SuppressWarnings("unused") final N node, | ||
@SuppressWarnings("unused") final N pathDestination) { | ||
return OptionalDouble.empty(); | ||
} | ||
|
||
/** | ||
* Provides the cost of a given edge.<br> | ||
* <br> | ||
* The base is the result of {@link Edge#getCost()}. Implementations are allowed to override this method in order to | ||
* modify the cost. | ||
* | ||
* @param edge The edge whose cost to provide | ||
* @param tentativeDistance The current tentative distance when relaxing this edge | ||
* | ||
* @return The cost of the given edge or empty if the module does not provide a cost | ||
*/ | ||
default OptionalDouble provideEdgeCost(@SuppressWarnings("unused") final E edge, | ||
@SuppressWarnings("unused") final double tentativeDistance) { | ||
return OptionalDouble.empty(); | ||
} | ||
|
||
/** | ||
* Whether or not the algorithm should abort computation of the shortest path. The method is called right after the | ||
* given node has been settled. | ||
* | ||
* @param tentativeDistance The tentative distance wrapper of the node that was settled | ||
* | ||
* @return {@code True} if the computation should be aborted, {@code false} if not | ||
*/ | ||
default boolean shouldAbort(@SuppressWarnings("unused") final TentativeDistance<N, E> tentativeDistance) { | ||
return false; | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
...nal/algorithms/shortestpath/EdgeCost.java → .../maglev/external/algorithms/EdgeCost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../algorithms/shortestpath/HasPathCost.java → ...glev/external/algorithms/HasPathCost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
de.zabuza.maglev/src/de/zabuza/maglev/external/algorithms/LandmarkProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.zabuza.maglev.external.algorithms; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Interface for classes that provide landmarks. Landmark are special nodes on a graph that can be used for distance | ||
* approximation. A good landmark should be a node that is important in the graph, i.e. is used for many shortest paths | ||
* between nodes. | ||
* | ||
* @param <E> The type of nodes and landmarks | ||
* | ||
* @author Daniel Tischner {@literal <[email protected]>} | ||
*/ | ||
@FunctionalInterface | ||
public interface LandmarkProvider<E> { | ||
/** | ||
* Provides the given amount of landmarks. Landmark selection might take a while depending on the size of the graph | ||
* and the amount to generate. | ||
* | ||
* @param amount The amount of landmarks to provide | ||
* | ||
* @return A collection consisting of the given amount of landmarks. If the given amount is more than the underlying | ||
* resource offers, the method should get all the resource offers. | ||
*/ | ||
Collection<E> getLandmarks(int amount); | ||
} |
31 changes: 31 additions & 0 deletions
31
de.zabuza.maglev/src/de/zabuza/maglev/external/algorithms/Metric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.zabuza.maglev.external.algorithms; | ||
|
||
/** | ||
* Interface for a metric defined on a given type of objects. | ||
* | ||
* @param <E> The type of objects the metric operates on | ||
* | ||
* @author Daniel Tischner {@literal <[email protected]>} | ||
*/ | ||
@FunctionalInterface | ||
public interface Metric<E> { | ||
/** | ||
* Computes the distance between the two given objects accordingly to the implementing metric. | ||
* <p> | ||
* The distance must satisfy the following properties: | ||
* <ul> | ||
* <li><b>non-negativity</b> - must be greater equals {@code 0}</li> | ||
* <li><b>identity-of-indiscernibles</b> - if the distance is {@code 0}, | ||
* the elements must be equal, according to their {@link E#equals(Object)}</li> | ||
* <li><b>symmetry</b> - {@code distance(a, b)} must be equals to {@code distance(b, a)}</li> | ||
* <li><b>triangle inequality</b> - {@code distance(a, c)} must be less equals | ||
* {@code distance(x, b) + distance(b, c)}</li> | ||
* </ul> | ||
* | ||
* @param first The first object | ||
* @param second The second object | ||
* | ||
* @return The distance between the two given objects | ||
*/ | ||
double distance(E first, E second); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.