PathPlan
Class MDP

java.lang.Object
  extended by PathPlan.MDP

public class MDP
extends java.lang.Object

A 2-dimensional MDP. Contains methods for managing per-state costs, converting between (x,y) pairs and state indices, and finding possible predecessors of a given state.


Field Summary
 int height
          Size of the MDP.
 int width
          Size of the MDP.
 
Constructor Summary
MDP(int w, int h, double c)
          Constructor.
 
Method Summary
 void addCost(int[] xs, int[] ys, int length, double c)
          Add a constant to the costs at a list of states.
 void clear()
          Reset all edge costs to default.
 java.awt.Image getCostImage(double mincost, double maxcost)
          Return a grayscale image of the state costs.
 double[] getCosts()
          Get the cost of every state as an array.
 double getDistance(int from, int to)
          Get the constant portion of the cost of moving in a straight line between states.
 double getLineCost(int startState, int endState)
          Accumulate total costs over a line.
 double getLineCost(int startState, int endState, double[] costs)
          Accumulate total costs over a line.
 double getStepCost()
          Get the per-step base cost.
 int getX(int index)
          Get the x coordinate corresponding to a state index.
 int getY(int index)
          Get the y coordinate corresponding to a state index.
 int numStates()
          How many states do we have?
 int predBound()
          Get a bound on the number of predecessors of a state.
 int predecessors(int state, int distState, boolean[] mask, int[] preds, double[] pcosts, double[] dists)
          Get information about the possible predecessors of a state.
 void set16connected()
          Set to a 16-connected (5x5 actions, removing duplicate directions) grid
 void set8connected()
          Set to an 8-connected (3x3 actions) grid
 void setCosts(double c)
          Initialize to a constant cost per step.
 void setCosts(double[] c, double baseCost)
          Set the state costs for the MDP.
 void setStepCost(double c)
          Set the per-step base cost.
 int stateIndex(int x, int y)
          Translate x, y into state index.
 int succBound()
          Get a bound on the number of successors of a state.
 int successors(int state, boolean[] mask, int[] succs, double[] scosts)
          Get information about the possible successors of a state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

public int width
Size of the MDP.


height

public int height
Size of the MDP.

Constructor Detail

MDP

public MDP(int w,
           int h,
           double c)
Constructor.

Method Detail

getCosts

public double[] getCosts()
Get the cost of every state as an array. Excludes the per-step base cost.


getStepCost

public double getStepCost()
Get the per-step base cost.


setStepCost

public void setStepCost(double c)
Set the per-step base cost.


setCosts

public void setCosts(double[] c,
                     double baseCost)
Set the state costs for the MDP.

Parameters:
c - The cost vector. Should be numStates elements long.
baseCost - Additional cost per step beyond what's in c.

setCosts

public void setCosts(double c)
Initialize to a constant cost per step.

Parameters:
c - The cost for a 1-unit step. (Some actions may move more than 1 unit (e.g. diagonal moves have length sqrt(2)) and so cost a multiple of this cost.)

addCost

public void addCost(int[] xs,
                    int[] ys,
                    int length,
                    double c)
Add a constant to the costs at a list of states.

Parameters:
xs - The x coordinates of the states to modify.
ys - The y coordinates of the states to modify.
length - Use this many elements of xs and ys.
c - The cost increment.

clear

public void clear()
Reset all edge costs to default.


getCostImage

public java.awt.Image getCostImage(double mincost,
                                   double maxcost)
Return a grayscale image of the state costs.

Parameters:
mincost - Scale so that mincost is intensity 0.
maxcost - Scale so that maxcost is intensity 1.

set8connected

public void set8connected()
Set to an 8-connected (3x3 actions) grid


set16connected

public void set16connected()
Set to a 16-connected (5x5 actions, removing duplicate directions) grid


getLineCost

public double getLineCost(int startState,
                          int endState)
Accumulate total costs over a line. That is, if we move in a straight line from startState to endState, accumulating costs in proportion to the time we spend in each grid cell, what is the total? Uses the stored state costs for the MDP.

Parameters:
startState - Starting position.
endState - Ending position.

getLineCost

public double getLineCost(int startState,
                          int endState,
                          double[] costs)
Accumulate total costs over a line. That is, if we move in a straight line from startState to endState, accumulating cost in proportion to the time we spend in each grid cell (at a rate costs[i] for cell i), what is the total?

Parameters:
startState - Starting position.
endState - Ending position.
costs - State costs.

getDistance

public double getDistance(int from,
                          int to)
Get the constant portion of the cost of moving in a straight line between states. (That is, use only the "additional cost per step" term from setCosts(double[], double).) This is faster to compute than the full answer which getLineCost(int, int) returns, and it is a lower bound under the assumption that all costs are positive.

Parameters:
from - Starting position.
to - Ending position.

predBound

public int predBound()
Get a bound on the number of predecessors of a state.


succBound

public int succBound()
Get a bound on the number of successors of a state.


successors

public final int successors(int state,
                            boolean[] mask,
                            int[] succs,
                            double[] scosts)
Get information about the possible successors of a state. Store the info in a preallocated array and return the number of states computed.

Parameters:
state - The state whose successors are required.
mask - Consider only successors s such that mask[s] is false.
succs - Store the successors in this array (which must be preallocated large enough, see succBound).
scosts - Store the cost of each successor in this array (which must be preallocated large enough, see succBound).

predecessors

public final int predecessors(int state,
                              int distState,
                              boolean[] mask,
                              int[] preds,
                              double[] pcosts,
                              double[] dists)
Get information about the possible predecessors of a state. Store the info in some preallocated arrays and return the number of predecessors computed.

Parameters:
state - The state whose predecessors are required.
distState - If nonnegative, compute a lower bound on the distance from each predecessor to distState and store in dists.
mask - Consider only predecessors p where mask[p]=true.
preds - Store the predecessors in this array (which must be preallocated large enough -- see predBound)
pcosts - For each predecessor p, store the cost of reaching state from p. (Must be preallocated also.)
dists - If distances were requested, store them in here. (Must be preallocated also.)

numStates

public int numStates()
How many states do we have?


stateIndex

public int stateIndex(int x,
                      int y)
Translate x, y into state index.


getX

public int getX(int index)
Get the x coordinate corresponding to a state index.


getY

public int getY(int index)
Get the y coordinate corresponding to a state index.