Class AStarHeuristicProvider
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.sea.BaseGraphCalulationService
-
- ch.sahits.game.openpatrician.engine.sea.AStarHeuristicProvider
-
- All Implemented Interfaces:
ch.sahits.game.graphic.image.model.MapGrid
@Component @Lazy public class AStarHeuristicProvider extends BaseGraphCalulationService
This singleton provides the heuristic for a specific map for the A* algorithm. Initially the heuristic from all nodes to all cities is calculated, based on:- The Eucledian distance
- Author:
- Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 31, 2015
-
-
Field Summary
-
Fields inherited from class ch.sahits.game.openpatrician.engine.sea.BaseGraphCalulationService
imageService, map, pointInterner
-
-
Constructor Summary
Constructors Constructor Description AStarHeuristicProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSourceNodeToHeuristic(javafx.geometry.Point2D source)Add a new target node to the heuristic.voidaddTargetNodeToHeuristic(javafx.geometry.Point2D target)Add a new target node to the heuristic.protected doublecalculateWeight(javafx.geometry.Point2D from, javafx.geometry.Point2D to)Calculate the weight between two nodes.javafx.geometry.Point2DfindClosest(javafx.geometry.Point2D point)Find the closest point in the graph for a defined point.java.util.Map<javafx.geometry.Point2D,com.carrotsearch.hppc.ObjectDoubleMap<javafx.geometry.Point2D>>getHeuristic()Retrieve the heuristic map.booleanheuristicForSourceAvailable(javafx.geometry.Point2D source)Check if the heuristic for a target location is calculated.voidregisterGameLoad(ch.sahits.game.openpatrician.event.GameStateChange gameStateChange)-
Methods inherited from class ch.sahits.game.openpatrician.engine.sea.BaseGraphCalulationService
getPoint, getSegments, getTangentialSegments, isOnSea
-
-
-
-
Method Detail
-
registerGameLoad
public void registerGameLoad(ch.sahits.game.openpatrician.event.GameStateChange gameStateChange)
-
calculateWeight
protected double calculateWeight(javafx.geometry.Point2D from, javafx.geometry.Point2D to)Description copied from class:BaseGraphCalulationServiceCalculate the weight between two nodes.- Specified by:
calculateWeightin classBaseGraphCalulationService- Parameters:
from- source nodeto- destination node- Returns:
- weight of the edge from node
fromtoto
-
heuristicForSourceAvailable
public boolean heuristicForSourceAvailable(javafx.geometry.Point2D source)
Check if the heuristic for a target location is calculated.- Parameters:
source- location- Returns:
- true if the heuristic is present.
-
getHeuristic
public java.util.Map<javafx.geometry.Point2D,com.carrotsearch.hppc.ObjectDoubleMap<javafx.geometry.Point2D>> getHeuristic()
Retrieve the heuristic map. This method is blocking while the heuristic is beeing calculated to ensure there are no out of date data contained.- Returns:
- Heuristic map for target locations to any location in the grid.
-
addTargetNodeToHeuristic
public void addTargetNodeToHeuristic(javafx.geometry.Point2D target)
Add a new target node to the heuristic.- Parameters:
target- location to be added.
-
addSourceNodeToHeuristic
public void addSourceNodeToHeuristic(javafx.geometry.Point2D source)
Add a new target node to the heuristic.- Parameters:
source- location to be added.
-
findClosest
public javafx.geometry.Point2D findClosest(javafx.geometry.Point2D point)
Find the closest point in the graph for a defined point.- Parameters:
point- for which the closest defined point should be looked up.- Returns:
- closest point to
point
-
-