Class 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
    The heuristic can also be queried if a source has it's heuristic calculated and calculate the heuristic values for that node. The heuristic may not be admissable, meaning that the value given in the heuristic for the distance between A and B may be larger than the actual distance, however the result should still be good enough.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2015 Created on Dec 31, 2015
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSourceNodeToHeuristic​(javafx.geometry.Point2D source)
      Add a new target node to the heuristic.
      void addTargetNodeToHeuristic​(javafx.geometry.Point2D target)
      Add a new target node to the heuristic.
      protected double calculateWeight​(javafx.geometry.Point2D from, javafx.geometry.Point2D to)
      Calculate the weight between two nodes.
      javafx.geometry.Point2D findClosest​(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.
      boolean heuristicForSourceAvailable​(javafx.geometry.Point2D source)
      Check if the heuristic for a target location is calculated.
      void registerGameLoad​(ch.sahits.game.openpatrician.event.GameStateChange gameStateChange)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AStarHeuristicProvider

        public AStarHeuristicProvider()
    • 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: BaseGraphCalulationService
        Calculate the weight between two nodes.
        Specified by:
        calculateWeight in class BaseGraphCalulationService
        Parameters:
        from - source node
        to - destination node
        Returns:
        weight of the edge from node from to to
      • 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