ai.planning.propositional
Class SequentialPlan

java.lang.Object
  extended by ai.planning.propositional.SequentialPlan
All Implemented Interfaces:
Plan<ai.krr.propositions.Atom>, SequentialPlan<ai.krr.propositions.Atom>, inf.compilers.SyntaxAdaptable

public class SequentialPlan
extends java.lang.Object
implements SequentialPlan<ai.krr.propositions.Atom>, inf.compilers.SyntaxAdaptable

This class class represents a SequentialPlan which is simply a sequence of Actions. Note that all Actions are totally ordered with respect to each other. A SequentialPlan is a solution to such a planning problem if and only if its execution in the initial state results in a state in which the goal is satisfied.

Author:
Gerhard Wickler

Field Summary
protected  java.util.LinkedList<Action> actions
          the sequence of Actions that constitute this SequentialPlan
protected  Domain domain
          the Domain defining the Actions in this plan
protected static inf.compilers.SyntaxAdaptor<SequentialPlan> ioAdaptor
          the SyntaxAdaptor used for input/output operations
protected  java.util.Map<ai.krr.NamedSymbol,Action> lblToActionMap
          the map from labels to Actions (possibly null)
 
Constructor Summary
SequentialPlan(Domain domain)
           This constructor creates a new empty SequentialPlan.
 
Method Summary
 void addFirst(Action action)
           This function adds the given Action to the front of this SequentialPlan.
 void addLast(Action action)
           This function adds the given Action to the end of this SequentialPlan.
 WorldState applyIn(WorldState<ai.krr.propositions.Atom> istate)
           This function computes a new WorldState that is the result of applying this SequentialPlan in the given state.
 SequentialPlan<ai.krr.propositions.Atom> asSequentialPlan()
           This function simply returns this Plan.
 void assignTo(ai.krr.NameSpace ns)
           This function can be used to generate labels for the Actions in this plan.
protected  SequentialPlan clone()
           This function creates a copy of this SequentialPlan that contains the same Actions as this SequentialPlan.
 void concatenate(SequentialPlan<ai.krr.propositions.Atom> plan)
           This function can be used to concatenate two plans.
 boolean equals(java.lang.Object obj)
           This function tests whether this and the given plan are equal.
 Action getAction(ai.krr.NamedSymbol label)
           This function can be used to retrieve the Action in this plan that has the given label.
 java.util.List<Action<ai.krr.propositions.Atom>> getActionSequence()
           This function returns the List of Actions that constitute this SequentialPlan.
 Domain getDomain()
           This function retrieves the Domain which contains the definitions of the ActionTypes of which the Actions in this Plan are instances.
 int hashCode()
           This function returns a hash value for this plan.
 int length()
           This function returns the current length of this SequentialPlan.
 void prettyPrint(int indent, java.io.Writer w, inf.compilers.SyntaxAdaptor sa)
           This function can be used write this sequential plan to the given Writer.
static SequentialPlan read(java.io.Reader r, inf.compilers.SyntaxAdaptor<SequentialPlan> sa)
           This function can be used to parse a Plan from the given Reader.
static SequentialPlan readFromFile(java.io.File file)
           This convenience function can be used to read a SequentialPlan from the given File.
static void setSyntax(inf.compilers.SyntaxAdaptor<SequentialPlan> sa)
           This function can be used to define the syntax with which instances of this class are written or read.
 boolean solves(Problem<ai.krr.propositions.Atom> plan)
           This function tests whether the given SequentialPlan constitutes a solution to this Problem.
 java.lang.String toString()
           This function returns a String representation of this SequentialPlan.
 void write(java.io.Writer w, inf.compilers.SyntaxAdaptor sa)
           This function can be used write this sequential plan to the given Writer.
 void writeToFile(java.io.File file)
           This convenience function can be used to write this Plan to the given File.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ioAdaptor

protected static inf.compilers.SyntaxAdaptor<SequentialPlan> ioAdaptor
the SyntaxAdaptor used for input/output operations


domain

protected Domain domain
the Domain defining the Actions in this plan


actions

protected java.util.LinkedList<Action> actions
the sequence of Actions that constitute this SequentialPlan


lblToActionMap

protected java.util.Map<ai.krr.NamedSymbol,Action> lblToActionMap
the map from labels to Actions (possibly null)

Constructor Detail

SequentialPlan

public SequentialPlan(Domain domain)

This constructor creates a new empty SequentialPlan.

Method Detail

clone

protected SequentialPlan clone()

This function creates a copy of this SequentialPlan that contains the same Actions as this SequentialPlan. Only the structure is new; the contained Actions are identical.

Overrides:
clone in class java.lang.Object
Returns:
a semi-shallow copy of this SequentialPlan

write

public void write(java.io.Writer w,
                  inf.compilers.SyntaxAdaptor sa)
           throws inf.compilers.ExpressivenessException,
                  java.io.IOException

This function can be used write this sequential plan to the given Writer. The syntax in which it is written is defined by the SyntaxAdaptor that is also given to this function.

Specified by:
write in interface inf.compilers.SyntaxAdaptable
Parameters:
w - the Writer to which this Problem is written
sa - the SyntaxAdaptor that determines the syntax
Throws:
inf.compilers.ExpressivenessException - if the syntax does not support every construct occurring in this Domain
java.io.IOException - if writing to the Writer fails

prettyPrint

public void prettyPrint(int indent,
                        java.io.Writer w,
                        inf.compilers.SyntaxAdaptor sa)
                 throws inf.compilers.ExpressivenessException,
                        java.io.IOException

This function can be used write this sequential plan to the given Writer. The syntax is the same as for normal writing. The only difference is the inclusion of extra space and newlines for better readability.

Specified by:
prettyPrint in interface inf.compilers.SyntaxAdaptable
Parameters:
indent - the amount of indentation for the first line
w - the Writer to which this Sentence is written
sa - the SyntaxAdaptor that determines the syntax
Throws:
inf.compilers.ExpressivenessException - if the syntax does not support every construct occurring in this Sentence
java.io.IOException - if writing to the Writer fails

asSequentialPlan

public SequentialPlan<ai.krr.propositions.Atom> asSequentialPlan()

This function simply returns this Plan.

Specified by:
asSequentialPlan in interface Plan<ai.krr.propositions.Atom>
Returns:
a SequentialPlan that corresponds to this Plan

getDomain

public Domain getDomain()

This function retrieves the Domain which contains the definitions of the ActionTypes of which the Actions in this Plan are instances.

Specified by:
getDomain in interface Plan<ai.krr.propositions.Atom>
Returns:
the Domain for which this Plan was created

applyIn

public WorldState applyIn(WorldState<ai.krr.propositions.Atom> istate)

This function computes a new WorldState that is the result of applying this SequentialPlan in the given state. This will be computed by applying the Actions in the SequentialPlan one after another in the order defined in the SequentialPlan. If an Action is not applicable in an intermediate state, the result will be null.

Specified by:
applyIn in interface Plan<ai.krr.propositions.Atom>
Parameters:
istate - the WorldState in which the SequentialPlan is to be applied
Returns:
a new WorldState that is the result of the state transition function applied to this WorldState

solves

public boolean solves(Problem<ai.krr.propositions.Atom> plan)

This function tests whether the given SequentialPlan constitutes a solution to this Problem. This is true iff the actions in the SequentialPlan applied to the initial state in the order defined in the SequentialPlan result in a state that satisfies the goal of this Problem.

Specified by:
solves in interface Plan<ai.krr.propositions.Atom>
Parameters:
plan - the SequentialPlan that may constitute a solution
Returns:
true iff the given SequentialPlan is a solution plan for this problem

getActionSequence

public java.util.List<Action<ai.krr.propositions.Atom>> getActionSequence()

This function returns the List of Actions that constitute this SequentialPlan.

Specified by:
getActionSequence in interface SequentialPlan<ai.krr.propositions.Atom>
Returns:
the Action sequence that defines this SequentialPlan

concatenate

public void concatenate(SequentialPlan<ai.krr.propositions.Atom> plan)

This function can be used to concatenate two plans. The result is a SequentialPlan that contains first this plan as its prefix and the given plan as its suffix. The length of the resulting plan will be the sum of the lengths of the two input plans.

Specified by:
concatenate in interface SequentialPlan<ai.krr.propositions.Atom>
Parameters:
plan - the plan that will be appended to this SequentialPlan

length

public int length()

This function returns the current length of this SequentialPlan.

Specified by:
length in interface SequentialPlan<ai.krr.propositions.Atom>
Returns:
the number of Actions in this SequentialPlan

addFirst

public void addFirst(Action action)

This function adds the given Action to the front of this SequentialPlan. If the SequentialPlan executed, this Action would be the first to be applied.

Parameters:
action - the new first Action of the SequentialPlan

addLast

public void addLast(Action action)

This function adds the given Action to the end of this SequentialPlan. If the SequentialPlan executed, this Action would be the last to be applied.

Parameters:
action - the new last Action of the SequentialPlan

assignTo

public void assignTo(ai.krr.NameSpace ns)

This function can be used to generate labels for the Actions in this plan. This will be useful if the plan is communicated to other agents that need to have a shared set of labels to refer to the Actions in the plan. To avoid duplicate definitions of labels by different agents, the given URI should include the unique name of the agent assigning this plan. If the given NameSpace is null, the generated labels will be internal NamedSymbols which is useful when the plan is to be written to file.

Parameters:
ns - the NameSpace to which the Symbols representing labels will belong (or null for internal NamedSymbols)

getAction

public Action getAction(ai.krr.NamedSymbol label)

This function can be used to retrieve the Action in this plan that has the given label. If there is no such action in this plan, the function will return null.

Parameters:
label - the NamedSymbol constituting the label of the Action
Returns:
the Action from this plan that has the given label, or null

writeToFile

public void writeToFile(java.io.File file)
                 throws java.io.IOException,
                        inf.compilers.ExpressivenessException

This convenience function can be used to write this Plan to the given File. Note that it actually pretty-prints this Plan. The SyntaxAdaptor used can specified using setSyntax(SyntaxAdaptor).

Parameters:
file - the File to which this SequentialPlan is to be written
Throws:
java.io.IOException - if writing to the File fails
inf.compilers.ExpressivenessException - if the SyntaxAdaptor used throws this Exception

toString

public java.lang.String toString()

This function returns a String representation of this SequentialPlan. The exact syntax is determined by the SyntaxAdaptor used, which can be set using setSyntax(SyntaxAdaptor). If the transformation causes an ExpressivenessException (if there are constructs in this SequentialPlan that cannot be expressed in the syntax) this function will return null.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this SequentialPlan

equals

public boolean equals(java.lang.Object obj)

This function tests whether this and the given plan are equal.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object this Plan is compared to
Returns:
whether they are equal

hashCode

public int hashCode()

This function returns a hash value for this plan.

Overrides:
hashCode in class java.lang.Object
Returns:
an integer that can be used for hashing

setSyntax

public static void setSyntax(inf.compilers.SyntaxAdaptor<SequentialPlan> sa)

This function can be used to define the syntax with which instances of this class are written or read. The default is the PPL syntax defined by a PplSequentialPlanAdaptor.

Parameters:
sa - the SyntaxAdaptor that defines the syntax for I/O operations

read

public static SequentialPlan read(java.io.Reader r,
                                  inf.compilers.SyntaxAdaptor<SequentialPlan> sa)
                           throws inf.compilers.ExpressivenessException,
                                  java.text.ParseException,
                                  java.io.IOException

This function can be used to parse a Plan from the given Reader. The syntax that is expected from the input and how this is transformed into a propositional sequential plan is determined by the given SyntaxAdaptor.

Parameters:
r - the Reader from which character input is parsed
sa - the SyntaxAdaptor that creates the SequentialPlan
Returns:
a new Domain corresponding to the given input
Throws:
inf.compilers.ExpressivenessException - if the syntax does not support every construct occurring in the input
java.text.ParseException - if the input contains syntax errors
java.io.IOException - if reading from the Reader fails

readFromFile

public static SequentialPlan readFromFile(java.io.File file)
                                   throws inf.compilers.ExpressivenessException,
                                          java.text.ParseException,
                                          java.io.IOException

This convenience function can be used to read a SequentialPlan from the given File. It uses the SyntaxAdaptor that can be set using setSyntax(SyntaxAdaptor) to perform this operation.

Parameters:
file - the File from which the SequentialPlan is to be read
Returns:
the SequentialPlan defined in the given file
Throws:
inf.compilers.ExpressivenessException - if the syntax does not support every construct occurring in the input
java.text.ParseException - if the input contains syntax errors
java.io.IOException - if reading from the File fails