NodeNameType
- The datatype for the graph's nodespublic class GraphWalker<NodeNameType>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
GraphWalker.NextNodeSelector<NodeNameType>
This interface defines the method needed by the GraphWalker class to
implement all features of graph walking _except_ the algorithm used to
select the next node to visit
|
static class |
GraphWalker.RandomWalker<NodeNameType>
This class implements the most simple walker which randomly selects from
the available edges.
|
Constructor and Description |
---|
GraphWalker(DirectedNodeEdgeGraph<NodeNameType> graph,
GraphWalker.NextNodeSelector<NodeNameType> selector)
Initializes a new graph walker with as-yet empty metrics
|
GraphWalker(DirectedNodeEdgeGraph<NodeNameType> graph,
GraphWalker.NextNodeSelector<NodeNameType> selector,
GraphMetrics<NodeNameType> metrics)
Initializes a new graph walker with the input values
|
Modifier and Type | Method and Description |
---|---|
NodeNameType |
getEndNode(int numSteps)
Returns the last node reached on a walk of numSteps steps starting from
current node
|
NodeNameType |
getEndNode(NodeNameType startNode,
int numSteps)
Returns the last node reached on a walk of numSteps steps starting from
startNode
|
java.util.Map<NodeNameType,java.lang.Integer> |
getEndNodes(NodeNameType startNode,
int numSteps,
int numTries)
After running numTries walk of numSteps starting from startNode, this
returns a map where the keys are all nodes reached at the end and the
values are the number of times those nodes were reached.
|
java.util.List<NodeNameType> |
getPath(int numSteps)
Returns the path traversed across numSteps steps of the walk from the
current start node.
|
java.util.List<NodeNameType> |
getPath(NodeNameType startNode,
int numSteps)
Returns the path traversed across numSteps steps of the walk from
startNode
|
static int |
probablisticSelect(DoubleArrayList weights,
java.util.Random r)
Helper method that returns the index of the probabilistically selected
input weight.
|
void |
setStartNode(int nodeId)
Sets the starting node (by id) for the next step (or series of steps)
|
void |
setStartNode(NodeNameType node)
Sets the start node (by name) for the next step (or series of steps)
|
public GraphWalker(DirectedNodeEdgeGraph<NodeNameType> graph, GraphWalker.NextNodeSelector<NodeNameType> selector)
graph
- The graph to walkselector
- The algorithm to use to select the next node in a walkpublic GraphWalker(DirectedNodeEdgeGraph<NodeNameType> graph, GraphWalker.NextNodeSelector<NodeNameType> selector, GraphMetrics<NodeNameType> metrics)
graph
- The graph to walkselector
- The algorithm to use to select the next node in a walkmetrics
- The metrics to usepublic void setStartNode(int nodeId)
nodeId
- The node to start atpublic void setStartNode(NodeNameType node)
node
- The node to start atpublic java.util.List<NodeNameType> getPath(int numSteps)
numSteps
- The number of steps to takepublic java.util.List<NodeNameType> getPath(NodeNameType startNode, int numSteps)
startNode
- The node to start fromnumSteps
- The number of steps to takepublic NodeNameType getEndNode(int numSteps)
numSteps
- The number of steps to takepublic NodeNameType getEndNode(NodeNameType startNode, int numSteps)
startNode
- The node to start fromnumSteps
- The number of steps to takepublic java.util.Map<NodeNameType,java.lang.Integer> getEndNodes(NodeNameType startNode, int numSteps, int numTries)
startNode
- The node to start from on every pathnumSteps
- The number of steps to take on any pathnumTries
- The number of paths to runpublic static int probablisticSelect(DoubleArrayList weights, java.util.Random r)
weights
- The relative weights of each choicer
- The instance of Random to use