lejos.robotics.pathfinding
Class RandomSelfGeneratingNode
java.lang.Object
lejos.robotics.pathfinding.Node
lejos.robotics.pathfinding.RandomSelfGeneratingNode
public class RandomSelfGeneratingNode
- extends Node
This Node is able to randomly generate its own neighbors via the getNeighbors() method. The number of neighbors
and possible distances to the neighbors are determined in the constructor. The first instance of this node is generally
the start node used in algorithms. The goal node is just a regular node that is automatically linked to this set
when the dynamically created nodes come within range of the goal node.
Note: Because the nodes are randomly generated, there is no guarantee they will come within range of the goal node
and successfully link up. However, in practice they will always connect if you use enough connections (minimum 3-4) and
a long enough maxDist.
- Author:
- BB
Fields inherited from class lejos.robotics.pathfinding.Node |
x, y |
Constructor Summary |
RandomSelfGeneratingNode(float x,
float y,
float maxDist,
int connections)
Creates a node that will randomly generate 'connections' number of neighbors when getNeighbors()
is called. |
RandomSelfGeneratingNode(float x,
float y,
float maxDist,
int connections,
Node goal)
Creates a node that will randomly generate 'connections' number of neighbors when getNeighbors()
is called. |
Method Summary |
java.util.Collection<Node> |
getNeighbors()
When this method is called the first time, it randomly generates a set of neighbors according to
the parameters in the constructor. |
Methods inherited from class lejos.robotics.pathfinding.Node |
addNeighbor, calculateG, calculateH, getF_Score, getG_Score, getPredecessor, neighbors, removeNeighbor, setG_Score, setH_Score, setPredecessor |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RandomSelfGeneratingNode
public RandomSelfGeneratingNode(float x,
float y,
float maxDist,
int connections)
- Creates a node that will randomly generate 'connections' number of neighbors when getNeighbors()
is called. These neighbors will be within range of 'maxDist'.
- Parameters:
x
- The x coordinate of this node.y
- The y coordinate of this node.maxDist
- The maximum x or y distance to create new nodes randomly.connections
- The number of neighbors to randomly generate and connect with.
RandomSelfGeneratingNode
public RandomSelfGeneratingNode(float x,
float y,
float maxDist,
int connections,
Node goal)
- Creates a node that will randomly generate 'connections' number of neighbors when getNeighbors()
is called. These neighbors will be within range of 'maxDist'.
- Parameters:
x
- The x coordinate of this node.y
- The y coordinate of this node.maxDist
- The maximum x or y distance to create new nodes randomly.connections
- The number of neighbors to randomly generate and connect with.goal
- The goal node which is added to this set and connected to any nodes within range.
getNeighbors
public java.util.Collection<Node> getNeighbors()
- When this method is called the first time, it randomly generates a set of neighbors according to
the parameters in the constructor. It then calls addNeighbor() for each one. The next time getNeighbors() is called
it will return the same set of neighbors it initially generated.
Each of these neighbors is a RandomSelfGeneratingNode too, so when their neighbors are requested they will also
self-generate a set of neighbors.
Each random node will also add the "parent" node to its list of neighboring nodes.
If a goal node was added, it checks if the node is within maxDist of the goal node. If it is, both the goal node and
this node add each other as neighbors.
- Overrides:
getNeighbors
in class Node
- Returns:
- a collection of RandomSelfGeneratingNode objects.