PathPlan
Class PathPlanner

java.lang.Object
  extended by PathPlan.PathPlanner

public class PathPlanner
extends java.lang.Object

Class to plan paths in a deterministic MDP with positive costs using Dijkstra's algorithm or A*. Plans "backwards" (ie, processes goals first and works towards start) so that we can handle multiple (disjunctive) goals.


Constructor Summary
PathPlanner()
           
 
Method Summary
 void addGoal(int node)
          Add a goal state.
 void addGoal(int node, double cost)
          Add a goal state with a specified cost.
 double costOf(int state)
          Get the planned cost of a state.
 boolean costOK(int state)
          Check whether we know the cost-to-go of a state.
 int getAction(int state)
          Get the next action in our plan.
 boolean getActionOK(int state)
          Check whether we've planned an action for a given state.
 int[] getPath(int state)
          Get the path from a state to the nearest goal.
 int[] getPath(int state, int[] path)
          Get the path from a state to the nearest goal.
 int[] getPolicy()
           
 int getStart()
          Get the start state.
 double[] getTotalCosts()
           
 boolean[] getWorking()
           
 void init(MDP m)
          Get ready to plan paths in a given MDP.
 boolean isGoal(int state)
          Check whether we're at a goal.
static void main(java.lang.String[] args)
           
 double plan()
          Plan using however many iterations it takes; equivalent to plan(int) with maxiter=0}.
 double plan(int maxiters)
          Find lowest-cost paths.
 int[] prunePath(int[] path)
          Delete nodes from a path to try to make it shorter.
 void setStart(int start)
          Set the start state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathPlanner

public PathPlanner()
Method Detail

init

public void init(MDP m)
Get ready to plan paths in a given MDP. We will use the MDP to decide how much storage to allocate, and later (in plan(int)) to compute the allowable predecessors for a given state.

Parameters:
m - The MDP.

setStart

public void setStart(int start)
Set the start state. Set to -1 (the default) to use Dijkstra's algorithm (and thereby plan for all possible start states at once). Setting to a nonnegative value selects A* planning instead, which attempts to focus the search to expand fewer nodes.

Parameters:
start - The desired starting state.

getStart

public int getStart()
Get the start state.


addGoal

public void addGoal(int node)
Add a goal state. This function should be called after init(PathPlan.MDP) and before plan(int), and may be called as many times as desired during this interval.

Parameters:
node - The goal node to add. The planning problem is over once we've reached any one of the goal nodes.

addGoal

public void addGoal(int node,
                    double cost)
Add a goal state with a specified cost. See addGoal(int) for restrictions.

Parameters:
node - The goal node to add.
cost - The cost of using this node to finish the planning problem.

plan

public double plan(int maxiters)
Find lowest-cost paths. This is the main computational function in the class: it repeatedly selects a state to process ("expand"), computes its cost-to-go and policy, and marks its predecessors for expansion at some future iteration. Planning is over when we have expanded the current start state (or all states, if the current start state is -1).

Parameters:
maxiters - Expand no more than this many nodes. Set to 0 to allow however many expansions it takes to finish planning.

plan

public double plan()
Plan using however many iterations it takes; equivalent to plan(int) with maxiter=0}.


getActionOK

public boolean getActionOK(int state)
Check whether we've planned an action for a given state.

Parameters:
state - Do we have an action for this state?

isGoal

public boolean isGoal(int state)
Check whether we're at a goal.

Parameters:
state - Is this state a goal?

costOK

public boolean costOK(int state)
Check whether we know the cost-to-go of a state.

Parameters:
state - Do we know the cost for this state?

getAction

public int getAction(int state)
Get the next action in our plan. Actions are labeled according to the state they end up in, so after a call to plan, we can follow a path by repeated calls to this function starting with the start state.

Parameters:
state - Get the action for this state.

getPath

public int[] getPath(int state,
                     int[] path)
Get the path from a state to the nearest goal. Like a bunch of calls to getAction.

Parameters:
state - The starting state.
path - Preallocated array to hold path, or null. Will be reallocated if necessary to hold all returned states.
Returns:
Returns path[], or the reallocated version of path[]. There will be a sentinel -1 after the end of the computed states if (and only if) there's extra space left.

getPath

public int[] getPath(int state)
Get the path from a state to the nearest goal. Equivalent to getPath(state, null).

Parameters:
state - The starting state.

prunePath

public int[] prunePath(int[] path)
Delete nodes from a path to try to make it shorter. Works only because the planner considers an 8-connected grid while straight lines in arbitrary directions make sense.

Parameters:
path - The path to prune.

costOf

public double costOf(int state)
Get the planned cost of a state.

Parameters:
state - How much does it cost to get to a goal from here?

getTotalCosts

public double[] getTotalCosts()

getWorking

public boolean[] getWorking()

getPolicy

public int[] getPolicy()

main

public static void main(java.lang.String[] args)