org.graphstream.algorithm
Class AStar.DefaultCosts

java.lang.Object
  extended by org.graphstream.algorithm.AStar.DefaultCosts
All Implemented Interfaces:
AStar.Costs
Enclosing class:
AStar

public static class AStar.DefaultCosts
extends Object
implements AStar.Costs

An implementation of the Costs interface that provide a default heuristic. It computes the G part using "weights" on edges. These weights must be stored in an attribute on edges. By default this attribute must be named "weight", but this can be changed. The weight attribute must be a number an must be translatable to a float value. This implementation always return 0 for the H value. This makes the A* algorithm an equivalent of the Dijkstra algorithm.


Constructor Summary
AStar.DefaultCosts()
          New default costs for the A* algorithm.
AStar.DefaultCosts(String weightAttributeName)
          New default costs for the A* algorithm.
 
Method Summary
 double cost(org.graphstream.graph.Node parent, org.graphstream.graph.Edge edge, org.graphstream.graph.Node next)
          The cost of moving from parent to next.
 double heuristic(org.graphstream.graph.Node node, org.graphstream.graph.Node target)
          The heuristic.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AStar.DefaultCosts

public AStar.DefaultCosts()
New default costs for the A* algorithm. The cost of each edge is obtained from a numerical attribute stored under the name "weight". This attribute must be a descendant of Number (Double, Float, Integer, etc.).


AStar.DefaultCosts

public AStar.DefaultCosts(String weightAttributeName)
New default costs for the A* algorithm. The cost of each edge is obtained from the attribute stored on each edge under the "weightAttributeName". This attribute must be a descendant of Number (Double, Float, Integer, etc.).

Parameters:
weightAttributeName - The name of cost attributes on edges.
Method Detail

heuristic

public double heuristic(org.graphstream.graph.Node node,
                        org.graphstream.graph.Node target)
The heuristic. This one always returns zero, therefore transforming this A* into the Dijkstra algorithm.

Specified by:
heuristic in interface AStar.Costs
Parameters:
node - A node.
target - The target node.
Returns:
The estimation.

cost

public double cost(org.graphstream.graph.Node parent,
                   org.graphstream.graph.Edge edge,
                   org.graphstream.graph.Node next)
The cost of moving from parent to next. If there is no cost attribute, the edge is considered to cost value "1".

Specified by:
cost in interface AStar.Costs
Parameters:
parent - The node we come from.
edge - The edge between parent and next.
next - The node we go to.
Returns:
The movement cost.


Copyright © 2011. All Rights Reserved.