Package fr.uga.pddl4j.parser
Class Expression<T>
java.lang.Object
fr.uga.pddl4j.parser.Expression<T>
- Type Parameters:
T
- The type of internal representation used. The parser used string presentation. The instantiation process used integer representation for efficiency.
- All Implemented Interfaces:
Locatable
,Serializable
,Iterable<Expression<T>>
public class Expression<T>
extends Object
implements Locatable, Iterable<Expression<T>>, Serializable
This class implements an expression. An expression defines a syntactical tree. It is used by the parser and during
the instantiation process to manipulate a planning problem.
- See Also:
- Serialized Form
-
Constructor Summary
ConstructorDescriptionCreates a new empty AND expression.Expression(Connector connector)
Creates a new expression with a specified connector.Expression(Expression<T> other)
Creates a new expression from another. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addArgument(Symbol<T> argument)
Adds an argument to this expression.boolean
addChild(Expression<T> exp)
Add a new child expression to this expression.boolean
addQuantifiedVariable(TypedSymbol<T> variable)
Adds a quantified variable to this expression.void
assign(Expression<T> exp)
Assigns a specified expression to this expression.boolean
contains(Expression<T> exp)
Returns if a specified expression is contains, i.e., is a sub-expression of this expression.boolean
Returns if the expression is equal to another object.void
Expands the quantified expressions contained in a specified expression.void
expandQuantifiedExpression(Map<T,Set<Symbol<T>>> domains, AtomicFormulaSimplifier<T> simplifier)
Expands the quantified expressions contained in a specified expression.Returns the arguments of the atomic formula represented by this expression.List<Expression<T>>
Returns the list of children of this expression.Returns the connector of this expression.Return the location of this expression.Returns the name of the preference associated to this expression.List<TypedSymbol<T>>
Returns the list of quantified variables of this expression.Returns the symbol to this expression.Returns the taskID associated to this expression.getTaskIDs(Expression<String> exp)
Returns the set of task IDs contains in an expression.Returns the time specifier of this expression.getValue()
Returns the numeric value of this expression.Returns the variable of this expression.int
hashCode()
Returns the hash code value of the expression.boolean
isLeaf()
Returns if this expression is a leaf of the syntax tree.boolean
Returns if this expression is a literal.boolean
Returns if this expression is malformed.boolean
Returnstrue
if the expression is a primitive task.iterator()
Returns an iterator over the children expressions of the expression. this iterator walks the syntax tree of the expression in depth first.boolean
remove(Expression<T> exp)
Removes all the occurrences of a specified expression contained in this expression and returnstrue
if and only if at least one occurrence was removed.void
setArguments(List<Symbol<T>> arguments)
Sets the argument of the atomic formula represented by this expression.void
setBegin(fr.uga.pddl4j.parser.lexer.Token begin)
Sets the begin line and column of the expression from a specified token.void
setChildren(List<Expression<T>> children)
Sets the list of children expressions of this expression.void
setConnector(Connector connective)
Set the connector of this expression.void
setEnd(fr.uga.pddl4j.parser.lexer.Token end)
Sets the end line and column of the expression from a specified token.void
setLocation(Location location)
Sets the location of this expression.void
setPrefName(Symbol<T> name)
Sets a name to the preference associated to this expression.void
setPrimtive(boolean flag)
Sets the boolean flag used to specified if the expression is a primitive task to a specified value.void
setQuantifiedVariables(List<TypedSymbol<T>> variables)
Sets the quantified variables of this expression.void
Sets a new symbol to this expression.void
Set the taskID associated to this expression.void
setTimeSpecifier(TimeSpecifier timeSpecifier)
Sets the time specifier of this expression.void
Set the numeric value of this expression.void
setVariable(Symbol<T> variable)
Sets a new variable to this expression.boolean
simplify()
This method simplify a specified expression.boolean
substitute(Symbol<T> var, Symbol<T> cons)
Substitutes all occurrence of a specified variable into an expression by a constant.boolean
substitute(Symbol<T> var, Symbol<T> cons, AtomicFormulaSimplifier<T> simplifier)
Substitutes all occurrence of a specified variable into an expression by a constant.void
toCNF()
Convert an expression in conjunctive normal form (CNF).void
toDNF()
Convert an expression in disjunctive normal form (DNF).void
toNNF()
Sets the expression into negative normal form.toString()
Returns a string representation of this node.Returns a string representation of this parser node.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Expression
Creates a new expression from another. This constructor creates a deep copy.- Parameters:
other
- the other expression.
-
Expression
Creates a new expression with a specified connector.- Parameters:
connector
- the connector.- See Also:
Connector
-
Expression
public Expression()Creates a new empty AND expression.
-
-
Method Details
-
getConnector
Returns the connector of this expression.- Returns:
- the connector of this expression.
-
setConnector
Set the connector of this expression.- Parameters:
connective
- the connective.
-
getSymbol
Returns the symbol to this expression. Expression with a symbol are predicate, function or task formula.- Returns:
- the symbol the new symbol of this expression. If this expression is not ATOM, a FUNCTION or TASK the returned symbol is null.
-
setSymbol
Sets a new symbol to this expression. Expression with a symbol are predicate, function or task formula.- Parameters:
symbol
- the new symbol of this expression.
-
getArguments
Returns the arguments of the atomic formula represented by this expression. Only expression with a symbol such as predicate, function or task formula have arguments.- Returns:
- the arguments of the atomic formula represented by this expression.
-
setArguments
Sets the argument of the atomic formula represented by this expression. Only expression with a symbol such as predicate, function or task formula have arguments.- Parameters:
arguments
- the arguments of the atomic formula represented by this expression.
-
addArgument
Adds an argument to this expression.- Parameters:
argument
- the argument to add.- Returns:
true
if the argument was addedfalse
otherwise.
-
getQuantifiedVariables
Returns the list of quantified variables of this expression.- Returns:
- the list of quantified variables of this expression.
-
setQuantifiedVariables
Sets the quantified variables of this expression.- Parameters:
variables
- the quantified variables of this expression.
-
addQuantifiedVariable
Adds a quantified variable to this expression.- Parameters:
variable
- the quantified variable to add.- Returns:
true
if the variable was addedfalse
otherwise.
-
getValue
Returns the numeric value of this expression.- Returns:
- the numeric value of this expression.
-
setValue
Set the numeric value of this expression.- Parameters:
value
- the numeric value of this expression.
-
getVariable
Returns the variable of this expression.- Returns:
- the variable of this expression.
-
setVariable
Sets a new variable to this expression.- Parameters:
variable
- the new variable to set.
-
getPrefName
Returns the name of the preference associated to this expression.- Returns:
- the name of the preference or
null
if the preference name was not initialized.
-
setPrefName
Sets a name to the preference associated to this expression.- Parameters:
name
- the name of the preference to set.
-
getTaskID
Returns the taskID associated to this expression. The taskID is use in HTN planning to make alias of task and in method constraints, e.g., hold-before, etc.- Returns:
- the taskID associated to this expression.
-
setTaskID
Set the taskID associated to this expression. The taskID is use in HTN planning to make alias of task and in method constraints, e.g., hold-before, etc.- Parameters:
taskID
- the taskID to set.
-
addChild
Add a new child expression to this expression.- Parameters:
exp
- the child to add- Returns:
true
if the expression was added;false
otherwise- Throws:
RuntimeException
- if the specified node is null
-
setChildren
Sets the list of children expressions of this expression.- Parameters:
children
- the children expression to set.
-
getChildren
Returns the list of children of this expression.- Returns:
- the list of children of this expression.
-
isPrimtive
public final boolean isPrimtive()Returnstrue
if the expression is a primitive task.- Returns:
true
if the expression is a primitive task,false
otherwise.
-
setPrimtive
public final void setPrimtive(boolean flag)Sets the boolean flag used to specified if the expression is a primitive task to a specified value.- Parameters:
flag
- the flag.
-
getTimeSpecifier
Returns the time specifier of this expression. The time specifiers are used to express the start or the end of task. It is always associated with the taskID of the expression.- Returns:
- the time specifier of this expression.
-
setTimeSpecifier
Sets the time specifier of this expression. The time specifiers are used to express the start or the end of task. It is always associated with the taskID of the expression.- Parameters:
timeSpecifier
- the time specifier to set.
-
getLocation
Return the location of this expression. The location is used by the parser to store the location of the expression the file and indicate warning or error. The location is null when expression is used during the instantiation process to optimize memory used.- Specified by:
getLocation
in interfaceLocatable
- Returns:
- the location of this expression.
- See Also:
Location
-
setLocation
Sets the location of this expression. The location is used by the parser to store the location of the expression the file and indicate warning or error. The location is null when expression is used during the instantiation process to optimize memory used.- Parameters:
location
- the location to set.
-
setBegin
public final void setBegin(fr.uga.pddl4j.parser.lexer.Token begin)Sets the begin line and column of the expression from a specified token. -
setEnd
public final void setEnd(fr.uga.pddl4j.parser.lexer.Token end)Sets the end line and column of the expression from a specified token. -
assign
Assigns a specified expression to this expression. After the method call the expression is equals to the expression in parameter. The assignment is swallow, i.e., the assignment does not make a deep copy of the content of the expression in parameter. After assignment, the specified expression is equal to this expression.- Parameters:
exp
- the expression to assigned to this expression.
-
isLiteral
public final boolean isLiteral()Returns if this expression is a literal. A literal is an atomic formula or a negated atomic formula.- Returns:
true
if this expression is a literalfalse
otherwise.
-
toNNF
public final void toNNF()Sets the expression into negative normal form. After the method call, negation can occur only before atomic formula with ATOM connector, time specifier (at start, at end, overall) can only occur before literal and method constraints (hold-before, hold-after and hold-between) can only occur before literal. -
expandQuantifiedExpression
Expands the quantified expressions contained in a specified expression.- Parameters:
domains
- the value domains associated with the type of quantified variables.
-
expandQuantifiedExpression
public void expandQuantifiedExpression(Map<T,Set<Symbol<T>>> domains, AtomicFormulaSimplifier<T> simplifier)Expands the quantified expressions contained in a specified expression.- Parameters:
domains
- the value domains associated with the type of quantified variables.simplifier
- the atomic formula simplifier used to simply atomic formula when it is possible in order to quickly cut off the instantiation of the logical formula. This parameter can be null. In that case no simplification will be done.
-
substitute
Substitutes all occurrence of a specified variable into an expression by a constant.- Parameters:
var
- the variable.cons
- the constant.- Returns:
true
if at least one occurrence of the specified was substituted;false
otherwise.
-
substitute
Substitutes all occurrence of a specified variable into an expression by a constant.- Parameters:
var
- the variable.cons
- the constant.simplifier
- the atomic formula simplifier used to simply atomic formula when it is possible in order to quickly cut off the instantiation of the logical formula. This parameter can be null. In that case no simplification will be done.- Returns:
true
if at least one occurrence of the specified was substituted;false
otherwise.
-
simplify
public final boolean simplify()This method simplify a specified expression. The rules of simplification are as below:- not true eqv false
- true ^ phi eqv phi
- false ^ phi eqv false
- true v phi eqv true
- false v phi eqv false
- not false eqv true
- phi ^ phi eqv phi
- phi v phi eqv phi
- phi ^ not phi eqv false
- phi v not phi eqv true
- x = x eqv true
- x = y eqv false
- Returns:
true
if the expression was simplified;false
otherwise.
-
contains
Returns if a specified expression is contains, i.e., is a sub-expression of this expression. More formally, returnstrue
if and only if this expression contains at least one subexpressions
such thats.equals(exp)
.- Parameters:
exp
- the expression to test.- Returns:
true
if the specified expressionexp
is a sub-expression of this expression;false
otherwise.
-
remove
Removes all the occurrences of a specified expression contained in this expression and returnstrue
if and only if at least one occurrence was removed.- Parameters:
exp
- the expression to remove.- Returns:
true
if the specified expressionexp
was removed;false
otherwise.
-
equals
Returns if the expression is equal to another object. The primitive flag and the task id are not used for comparison.- Overrides:
equals
in classObject
- Parameters:
object
- the other object.- See Also:
Object.equals(java.lang.Object)
-
hashCode
public int hashCode()Returns the hash code value of the expression.- Overrides:
hashCode
in classObject
- Returns:
- the hash code value of the expression.
- See Also:
Object.hashCode()
-
isMalformedExpression
public final boolean isMalformedExpression()Returns if this expression is malformed. An expression is considered as well in the following cases:- OR and AND expressions have to have all their child well-formed.
- EQUAL_ATOM expressions are well-formed if the expression contains an atom of at least two symbols.
- Quantified expressions (EXISTS, FORALL) is well formed if it has at least one quantified variable and one child expression.
- IMPLY, WHEN, EQUAL_COMPARISON, LESS_COMPARISON, LESS_OR_EQUAL_COMPARISON, GREATER_COMPARISON, GREATER_OR_EQUAL_COMPARISON, ASSIGN, INCREASE, DECREASE, SCALE_UP, SCALE_DOWN, MULTIPLICATION, DIVISION, MINUS, PLUS, SOMETIME_AFTER_CONSTRAINT, SOMETIME_BEFORE_CONSTRAINT expressions are well-formed if they have to child and both child are well-formed.
- NOT, UMINUS, AT_START, AT_END, OVER_ALL, MINIMIZE, MAXIMIZE, F_EXP_T, F_EXP, AT_END_METHOD_CONSTRAINT, AT_START_METHOD_CONSTRAINT, ALWAYS_METHOD_CONSTRAINT, AT_MOST_ONCE_METHOD_CONSTRAINT, SOMETIME_METHOD_CONSTRAINT expression are well-formed if they have on child and if it is well-formed.
- ATOM, TASKS, and F_HEAD expressions without any symbols as arguments are considered as well formed.
- TIMED_LITERAL, WITHIN_CONSTRAINT, HOLD_AFTER_CONSTRAINT, HOLD_BEFORE_METHOD_CONSTRAINT, HOLD_AFTER_METHOD_CONSTRAINT, SOMETIME_BEFORE_METHOD_CONSTRAINT, SOMETIME_AFTER_METHOD_CONSTRAINT expressions are considered as well-formed if they have well-formed child and a time value.
- HOLD_DURING_CONSTRAINT, HOLD_BETWEEN_METHOD_CONSTRAINT, HOLD_DURING_METHOD_CONSTRAINT expressions are well-formed if they have two child well-formed and an time interval value.
- ALWAYS_WITHIN expression must have at least two children to be considered as well formed and time interval value.
- NUMBER expressions are considered is they have a value.
- TIME_VAR, IS_VIOLATED exprssions are always considered as well-formed
- Returns:
true
if the expression is malformed;false
otherwise.
-
toString
Returns a string representation of this node.- Overrides:
toString
in classObject
- Returns:
- a string representation of this node.
- See Also:
Object.toString()
-
toString
Returns a string representation of this parser node.- Parameters:
baseOffset
- the offset white space from the left used for indentation.- Returns:
- a string representation of this parser node.
- Throws:
MalformedExpressionException
- if the expression is malformed.
-
toCNF
public void toCNF()Convert an expression in conjunctive normal form (CNF). -
toDNF
public void toDNF()Convert an expression in disjunctive normal form (DNF). -
getTaskIDs
Returns the set of task IDs contains in an expression.- Parameters:
exp
- the expression.- Returns:
- the set of task IDs contains in exp.
-
isLeaf
public final boolean isLeaf()Returns if this expression is a leaf of the syntax tree. An expression is a leaf if it is an ATOM, a TASK, a FN_HEAD, an EQUAL_ATOM, a TASK_ID, a TIMED_TASK_ID, a TIME_VAR, a NUMBER, TRUE or FALSE.- Returns:
- if this expression is a leaf of the syntax tree.
-
iterator
Returns an iterator over the children expressions of the expression. this iterator walks the syntax tree of the expression in depth first.
-