Class PlanGraph

java.lang.Object
edu.uky.ai.planning.pg.PlanGraph

public class PlanGraph extends Object

plan graph is a data structure that compresses the state space of a planning problem into something that represents possible future states. It is a directed, leveled graph with two kinds of nodes:

A LiteralNode represents a fact:

  • A literal node exists at level 0 iff it is true in the initial state.
  • A literal node exists at level n > 0 if it exists at level n.
  • A literal node exists at level n > 0 if there exists a step node a level n - 1 which has that literal as an effect.

A StepNode represents a step:

  • No step nodes exist at level 0.
  • A step node exists at level n > 0 if all its preconditions appear at level n - 1.

Node that a plan graph must be initialized to some state before it can be used. This method resets the plan graph and determines which literals are true at level 0.

In order to save a significant amount of memory, there is only 1 object for each literal node and each step node (rather than 1 per level at which that literal or step appears). A node is simply marked with the earliest level at which it appears, since it will continue to appear at all future levels. If a literal or step has not appeared yet, it's level is set to -1 and it is said not to exist (even though it still resides in memory for possible later use).

Note that a plan graph can be built with or without persistence steps and with or without mutexes.

Note that this implementation only computes static mutexes (ones that must always exist). It does not compute mytexes for competing needs or inconsistent support.

Author:
Stephen G. Ware
  • Field Details

  • Constructor Details

    • PlanGraph

      public PlanGraph(StateSpaceProblem problem, boolean persistence, boolean mutexes)
      Constructs a new plan graph using all possible steps for step nodes.
      Parameters:
      problem - the problem whose steps should be used as step nodes
      persistence - whether or not persistence steps should be generated
      mutexes - whether or not mutexes should be calculated
    • PlanGraph

      public PlanGraph(Problem problem, boolean persistence, boolean mutexes)
      Constructs a plan graph using all possible steps that could occur as the step nodes.
      Parameters:
      problem - the problem
      persistence - whether or not persistence steps should be generated
      mutexes - whether or not mutexes should be calculated
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get

      public LiteralNode get(Literal literal)
      Returns a literal object's node in this graph.
      Parameters:
      literal - the literal
      Returns:
      the literal's corresponding node
    • get

      public StepNode get(Step step)
      Returns a step object's node in this graph.
      Parameters:
      step - the step
      Returns:
      the step's corresponding node
    • initialize

      public void initialize(State initial)
      Resets the graph to have only level 0, which will include exactly those literals which are true in the given state.
      Parameters:
      initial - any state
    • extend

      public void extend()
      Adds one new level to the graph.
    • size

      public int size()
      Returns the number of levels in this graph.
      Returns:
      the number of levels
    • getLevel

      public Level getLevel(int number)
      Returns a level object for the level of the given index.
      Parameters:
      number - the index of the requested level
      Returns:
      the level
      Throws:
      IndexOutOfBoundsException - if the requested level does not exist in this graph
    • goalAchieved

      public boolean goalAchieved()
      Tests whether all the problem's goal literals exist at the highest level of the graph.
      Returns:
      true if all goals exist, false otherwise
    • hasLeveledOff

      public boolean hasLeveledOff()
      Tests whether or not the graph has leveled off (meaning that no new literals or steps will appear if a new level is added).
      Returns:
      true if the graph has leveled off, false otherwise