|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ai.planning.propositional.SequentialPlan
public class SequentialPlan
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.
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 |
---|
protected static inf.compilers.SyntaxAdaptor<SequentialPlan> ioAdaptor
protected Domain domain
protected java.util.LinkedList<Action> actions
protected java.util.Map<ai.krr.NamedSymbol,Action> lblToActionMap
Constructor Detail |
---|
public SequentialPlan(Domain domain)
This constructor creates a new empty SequentialPlan.
Method Detail |
---|
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.
clone
in class java.lang.Object
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.
write
in interface inf.compilers.SyntaxAdaptable
w
- the Writer to which this Problem is writtensa
- the SyntaxAdaptor that determines the syntax
inf.compilers.ExpressivenessException
- if the syntax does not support every
construct occurring in this Domain
java.io.IOException
- if writing to the Writer failspublic 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.
prettyPrint
in interface inf.compilers.SyntaxAdaptable
indent
- the amount of indentation for the first linew
- the Writer to which this Sentence is writtensa
- the SyntaxAdaptor that determines the syntax
inf.compilers.ExpressivenessException
- if the syntax does not support every
construct occurring in this Sentence
java.io.IOException
- if writing to the Writer failspublic SequentialPlan<ai.krr.propositions.Atom> asSequentialPlan()
This function simply returns this Plan.
asSequentialPlan
in interface Plan<ai.krr.propositions.Atom>
public Domain getDomain()
This function retrieves the Domain which contains the definitions of the ActionTypes of which the Actions in this Plan are instances.
getDomain
in interface Plan<ai.krr.propositions.Atom>
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.
applyIn
in interface Plan<ai.krr.propositions.Atom>
istate
- the WorldState in which the SequentialPlan is to be applied
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.
solves
in interface Plan<ai.krr.propositions.Atom>
plan
- the SequentialPlan that may constitute a solution
public java.util.List<Action<ai.krr.propositions.Atom>> getActionSequence()
This function returns the List of Actions that constitute this SequentialPlan.
getActionSequence
in interface SequentialPlan<ai.krr.propositions.Atom>
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.
concatenate
in interface SequentialPlan<ai.krr.propositions.Atom>
plan
- the plan that will be appended to this SequentialPlanpublic int length()
This function returns the current length of this SequentialPlan.
length
in interface SequentialPlan<ai.krr.propositions.Atom>
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.
action
- the new first Action of the SequentialPlanpublic 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.
action
- the new last Action of the SequentialPlanpublic 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.
ns
- the NameSpace to which the Symbols representing labels will
belong (or null for internal NamedSymbols)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.
label
- the NamedSymbol constituting the label of the Action
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)
.
file
- the File to which this SequentialPlan is to be written
java.io.IOException
- if writing to the File fails
inf.compilers.ExpressivenessException
- if the SyntaxAdaptor used throws this Exceptionpublic 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.
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
This function tests whether this and the given plan are equal.
equals
in class java.lang.Object
obj
- the Object this Plan is compared to
public int hashCode()
This function returns a hash value for this plan.
hashCode
in class java.lang.Object
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
.
sa
- the SyntaxAdaptor that defines the syntax for I/O operationspublic 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.
r
- the Reader from which character input is parsedsa
- the SyntaxAdaptor that creates the SequentialPlan
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 failspublic 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.
file
- the File from which the SequentialPlan is to be read
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |