ai.planning.propositional
Class PplProblemAdaptor

java.lang.Object
  extended by ai.planning.propositional.PplProblemAdaptor
All Implemented Interfaces:
inf.compilers.SyntaxAdaptor<Problem>

public class PplProblemAdaptor
extends java.lang.Object
implements inf.compilers.SyntaxAdaptor<Problem>

This class is an adaptor between the ai.planning.propositional.Problem class that can be used as an internal representation for planning problems and its external form as defined by the PPL (Propositional Planning Language) syntax as described below.

Writing

The syntax used here is a Lisp-like syntax in which every expression is a list that is enclosed in brackets. For example, the definition of a problem is a list consisting of the symbol define followed by lists specifying the problem name, the domain for which this problem is defined, the initial state, and the goal to be achieved. The problem name is given as a list containing the symbol problem optionally followed by a name for the domain. Note that the name will be ignored by the internal representation. The domain is given by a list beginning with the keyword :domain followed by the name of the domain. This must be a known Domain, meaning the Domain must be defined before a problem in that Domain can be defined. This syntax can be described more formally as follows:

 <Problem>     ::= '(' define <ProblemName> 
                      <DomainRef> <InitialState> <GoalSpec> ')'
 <ProblemName> ::= '(' problem [<name>] ')'
 <DomainRef>   ::= '(' :domain <name> ')'
 

The initial world state is given to the problem as a list beginning with the keyword :init. The remainder of the list enumerates exactly those propositional Atoms that are true in the initial state. An Atom not occurring in this list is considered false in the initial state. Formally, the syntax is:

 <InitialState> ::= '(' :init <Atom>* ')'
 

Syntactically, the goal looks almost like the initial state, except that the keyword used is :goal. The Atoms in the list are the propositions that must hold in the state that results from the application of a solution plan to this problem in the initial state.

 <GoalSpec> ::= '(' :goal <Atom>* ')'
 

Reading

A number of properties can be used modify the behaviour of this SyntaxAdaptor. Symbols are case-sensitive by default, which can be changed by setting the property case-sensitive to false. Similarly the property namespace-aware determines whether symbols are expected to belong to namespaces.

The remaining properties can be used to set the string used for a single indent (two spaces by default) and the maximal line width. Both of these properties are used for pretty-printing only.

property possible values default
case-sensitive true, false true
namespace-aware true, false true
indent-string any string "  "
line-width positive int 80

Author:
Gerhard Wickler
See Also:
PplDomainAdaptor

Field Summary
protected static inf.compilers.LexicalAnalyzer.TokenType closebracketTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType domainTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType goalTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType ignorableTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType initTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType openbracketTT
          the token types used
protected static inf.compilers.LexicalAnalyzer.TokenType problemTT
          the token types used
protected  java.util.Properties props
          the properties used for reading and writing
protected  inf.compilers.LexicalAnalyzer scanner
          the lexical analyzer used for tokenizing the input
 
Constructor Summary
PplProblemAdaptor()
           This constructor creates a SyntaxAdaptor that can be used to read propositional planning problems in the PPL syntax and create a propositional Problem for it, or it can be used to write out a propositional Problem in the PPL syntax.
 
Method Summary
protected  PplDomainAdaptor clone()
           This class does not support cloning and an Exception will be thrown if this method is called.
 java.lang.Class<Problem> getInternalClass()
           This function returns the Class that holds the internal representation this adaptor translates to and from.
 java.lang.String getProperty(java.lang.String key)
           This function gets the property that is associated with the given key.
 java.lang.String getSyntaxName()
           This function returns the name that should identify the syntactical language that this adaptor translates to and from.
protected static Goal parseGoal(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props)
           This function reads tokens from the given LexicalAnalyzer and attempts to create a Goal that corresponds to the parsed tokens.
protected static WorldState parseInitialState(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props)
           This function reads tokens from the given LexicalAnalyzer and attempts to create a state that corresponds to the parsed tokens.
protected static Problem parseProblem(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props)
           This function reads tokens from the given LexicalAnalyzer and attempts to create a Problem that corresponds to the parsed tokens.
 void prettyPrint(int indent, Problem problem, java.io.Writer w)
           This function takes a Problem which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the PPL syntax.
protected static void prettyPrintGoalSpec(int indent, Goal goal, java.io.Writer w, java.util.Properties props)
           This function writes the given Goal to the given Writer, using the given Properties.
protected static void prettyPrintInitialState(int indent, WorldState state, java.io.Writer w, java.util.Properties props)
           This function writes the given initial WorldState to the given Writer, using the given Properties.
protected static void prettyPrintProblem(int indent, Problem problem, java.io.Writer w, java.util.Properties props)
           This function writes the given Problem to the given Writer, using the given Properties.
 Problem read(java.io.Reader r)
           This function attempts to parse characters from the given Reader until a Problem that represents an object in the internal representation has been parsed.
 void setProperty(java.lang.String key, java.lang.String value)
           This function sets the property associated with the given key to the given value.
 void write(Problem problem, java.io.Writer w)
           This function takes a Problem which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the PPL syntax.
protected static void writeGoalSpec(Goal goal, java.io.Writer w, java.util.Properties props)
           This function writes the given Goal to the given Writer, using the given Properties.
protected static void writeInitialState(WorldState state, java.io.Writer w, java.util.Properties props)
           This function writes the given initial WorldState to the given Writer, using the given Properties.
protected static void writeProblem(Problem problem, java.io.Writer w, java.util.Properties props)
           This function writes the given Problem to the given Writer, using the given Properties.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ignorableTT

protected static inf.compilers.LexicalAnalyzer.TokenType ignorableTT
the token types used


openbracketTT

protected static inf.compilers.LexicalAnalyzer.TokenType openbracketTT
the token types used


closebracketTT

protected static inf.compilers.LexicalAnalyzer.TokenType closebracketTT
the token types used


problemTT

protected static inf.compilers.LexicalAnalyzer.TokenType problemTT
the token types used


domainTT

protected static inf.compilers.LexicalAnalyzer.TokenType domainTT
the token types used


initTT

protected static inf.compilers.LexicalAnalyzer.TokenType initTT
the token types used


goalTT

protected static inf.compilers.LexicalAnalyzer.TokenType goalTT
the token types used


scanner

protected inf.compilers.LexicalAnalyzer scanner
the lexical analyzer used for tokenizing the input


props

protected java.util.Properties props
the properties used for reading and writing

Constructor Detail

PplProblemAdaptor

public PplProblemAdaptor()

This constructor creates a SyntaxAdaptor that can be used to read propositional planning problems in the PPL syntax and create a propositional Problem for it, or it can be used to write out a propositional Problem in the PPL syntax.

Method Detail

clone

protected PplDomainAdaptor clone()
                          throws java.lang.CloneNotSupportedException

This class does not support cloning and an Exception will be thrown if this method is called.

Overrides:
clone in class java.lang.Object
Returns:
nothing
Throws:
java.lang.CloneNotSupportedException - will be thrown

getInternalClass

public java.lang.Class<Problem> getInternalClass()

This function returns the Class that holds the internal representation this adaptor translates to and from.

Specified by:
getInternalClass in interface inf.compilers.SyntaxAdaptor<Problem>
Returns:
the internal representation Class adapted to

getSyntaxName

public java.lang.String getSyntaxName()

This function returns the name that should identify the syntactical language that this adaptor translates to and from.

Specified by:
getSyntaxName in interface inf.compilers.SyntaxAdaptor<Problem>
Returns:
the name of the language adapted to

write

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

This function takes a Problem which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the PPL syntax.

Specified by:
write in interface inf.compilers.SyntaxAdaptor<Problem>
Parameters:
problem - the planning Problem to be written
w - the Writer to which the syntactical translation is written
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given statement
java.io.IOException - if writing to the given Writer fails

prettyPrint

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

This function takes a Problem which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the PPL syntax. Additional whitespace is added to increase readability.

Specified by:
prettyPrint in interface inf.compilers.SyntaxAdaptor<Problem>
Parameters:
indent - the amount of indentation for the first line
problem - the planning Problem to be written
w - the Writer to which the syntactical translation is written
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given statement
java.io.IOException - if writing to the given Writer fails

read

public Problem read(java.io.Reader r)
             throws inf.compilers.ExpressivenessException,
                    java.text.ParseException,
                    java.io.IOException

This function attempts to parse characters from the given Reader until a Problem that represents an object in the internal representation has been parsed.

Specified by:
read in interface inf.compilers.SyntaxAdaptor<Problem>
Parameters:
r - the Reader from which the representation is to be parsed
Returns:
the target internal representation
Throws:
inf.compilers.ExpressivenessException - if the internal representation class is not expressive enough for the given statement
java.text.ParseException - if there is a syntax error in the given string
java.io.IOException - if reading from the Reader fails

getProperty

public java.lang.String getProperty(java.lang.String key)

This function gets the property that is associated with the given key. Not e that the key should not be null.

Specified by:
getProperty in interface inf.compilers.SyntaxAdaptor<Problem>
Returns:
the property for the given key (or null if undefined)

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)

This function sets the property associated with the given key to the given value. The given key must not be null, but the value may be.

Specified by:
setProperty in interface inf.compilers.SyntaxAdaptor<Problem>
Parameters:
key - the key with which the value is associated
value - the associated value

writeProblem

protected static void writeProblem(Problem problem,
                                   java.io.Writer w,
                                   java.util.Properties props)
                            throws inf.compilers.ExpressivenessException,
                                   java.io.IOException

This function writes the given Problem to the given Writer, using the given Properties. The syntax used is as follows:

 <Problem>     ::= '(' define <ProblemName> 
                      <DomainRef> <InitialState> <GoalSpec> ')'
 <ProblemName> ::= '(' problem [<name>] ')'
 <DomainRef>   ::= '(' :domain <name> ')'
 

Parameters:
problem - the planning Problem to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given Problem
java.io.IOException - if writing to the given Writer fails

prettyPrintProblem

protected static void prettyPrintProblem(int indent,
                                         Problem problem,
                                         java.io.Writer w,
                                         java.util.Properties props)
                                  throws inf.compilers.ExpressivenessException,
                                         java.io.IOException

This function writes the given Problem to the given Writer, using the given Properties. The syntax is the same as for writing.

Parameters:
indent - the amount of indentation for the first line
problem - the planning Problem to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given Problem
java.io.IOException - if writing to the given Writer fails

writeInitialState

protected static void writeInitialState(WorldState state,
                                        java.io.Writer w,
                                        java.util.Properties props)
                                 throws inf.compilers.ExpressivenessException,
                                        java.io.IOException

This function writes the given initial WorldState to the given Writer, using the given Properties. The syntax used is as follows:

 <InitialState> ::= '(' :init <Atom>* ')'
 

Parameters:
state - the WorldState to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given WorldState
java.io.IOException - if writing to the given Writer fails

prettyPrintInitialState

protected static void prettyPrintInitialState(int indent,
                                              WorldState state,
                                              java.io.Writer w,
                                              java.util.Properties props)
                                       throws inf.compilers.ExpressivenessException,
                                              java.io.IOException

This function writes the given initial WorldState to the given Writer, using the given Properties. The syntax is the same as for writing.

Parameters:
indent - the amount of indentation for the first line
state - the initial state to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given WorldState
java.io.IOException - if writing to the given Writer fails

writeGoalSpec

protected static void writeGoalSpec(Goal goal,
                                    java.io.Writer w,
                                    java.util.Properties props)
                             throws inf.compilers.ExpressivenessException,
                                    java.io.IOException

This function writes the given Goal to the given Writer, using the given Properties. The syntax used is as follows:

 <GoalSpec> ::= '(' :goal <Atom>* ')'
 

Parameters:
goal - the Goal to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given Goal
java.io.IOException - if writing to the given Writer fails

prettyPrintGoalSpec

protected static void prettyPrintGoalSpec(int indent,
                                          Goal goal,
                                          java.io.Writer w,
                                          java.util.Properties props)
                                   throws inf.compilers.ExpressivenessException,
                                          java.io.IOException

This function writes the given Goal to the given Writer, using the given Properties. The syntax is the same as for writing.

Parameters:
indent - the amount of indentation for the first line
goal - the Goal to be written
w - the Writer to which the character representation is written
props - the Properties determining the exact syntax
Throws:
inf.compilers.ExpressivenessException - if the syntactical language cannot represent the given Goal
java.io.IOException - if writing to the given Writer fails

parseProblem

protected static Problem parseProblem(inf.compilers.LexicalAnalyzer scanner,
                                      java.util.Properties props)
                               throws inf.compilers.ExpressivenessException,
                                      java.text.ParseException,
                                      java.io.IOException

This function reads tokens from the given LexicalAnalyzer and attempts to create a Problem that corresponds to the parsed tokens. The given properties determine the exact syntax.

 <Problem>     ::= '(' define <ProblemName> 
                      <DomainRef> <InitialState> <GoalSpec> ')'
 <ProblemName> ::= '(' problem [<name>] ')'
 <DomainRef>   ::= '(' :domain <name> ')'
 

Parameters:
scanner - the LexicalAnalyzer from which tokens are parsed
props - the properties for parsing
Returns:
the Problem that represents the parsed input
Throws:
inf.compilers.ExpressivenessException - if the syntactical language uses features not supported by the internal representation
java.text.ParseException - if the input contains a syntactical error
java.io.IOException - if reading from the Reader fails

parseInitialState

protected static WorldState parseInitialState(inf.compilers.LexicalAnalyzer scanner,
                                              java.util.Properties props)
                                       throws inf.compilers.ExpressivenessException,
                                              java.text.ParseException,
                                              java.io.IOException

This function reads tokens from the given LexicalAnalyzer and attempts to create a state that corresponds to the parsed tokens. The given properties determine the exact syntax.

 <InitialState> ::= '(' :init <Atom>* ')'
 

Parameters:
scanner - the LexicalAnalyzer from which tokens are parsed
props - the properties for parsing
Returns:
the WorldState that represents the parsed input
Throws:
inf.compilers.ExpressivenessException - if the syntactical language uses features not supported by the internal representation
java.text.ParseException - if the input contains a syntactical error
java.io.IOException - if reading from the Reader fails

parseGoal

protected static Goal parseGoal(inf.compilers.LexicalAnalyzer scanner,
                                java.util.Properties props)
                         throws inf.compilers.ExpressivenessException,
                                java.text.ParseException,
                                java.io.IOException

This function reads tokens from the given LexicalAnalyzer and attempts to create a Goal that corresponds to the parsed tokens. The given properties determine the exact syntax.

 <GoalSpec> ::= '(' :goal <Atom>* ')'
 

Parameters:
scanner - the LexicalAnalyzer from which tokens are parsed
props - the properties for parsing
Returns:
the Goal that represents the parsed input
Throws:
inf.compilers.ExpressivenessException - if the syntactical language uses features not supported by the internal representation
java.text.ParseException - if the input contains a syntactical error
java.io.IOException - if reading from the Reader fails