JSHOP2
Class DelAddForAll

java.lang.Object
  extended by JSHOP2.CompileTimeObject
      extended by JSHOP2.DelAddElement
          extended by JSHOP2.DelAddForAll

public class DelAddForAll
extends DelAddElement

Each ForAll element in the delete/add list of an operator both at compile time and run time is represented as an instance of this class.

Version:
1.0.3
Author:
Okhtay Ilghami, http://www.cs.umd.edu/~okhtay

Field Summary
private  Predicate[] atoms
          The atoms to be deleted/added.
private static int classCnt
          The number of objects already instantiated from this class.
private  int cnt
          The number of objects already instantiated from this class before this object was instantiated.
private  LogicalExpression exp
          The precondtion of the ForAll statement at compile time is represented by this variable.
private  Precondition pre
          The precondtion of the ForAll statement at run time is represented by this variable.
 
Fields inherited from class JSHOP2.CompileTimeObject
endl
 
Constructor Summary
DelAddForAll(LogicalExpression expIn, java.util.Vector<Predicate> atomsIn)
          To initialize this ForAll delete/add element at compile time.
DelAddForAll(Precondition preIn, Predicate[] atomsIn)
          To initialize this ForAll delete/add element at run time.
 
Method Summary
 void add(State s, Term[] binding, java.util.Vector[] delAddList)
          To add the atoms of this ForAll delete/add element to the current state of the world.
 boolean del(State s, Term[] binding, java.util.Vector[] delAddList)
          To delete the atoms of this ForAll delete/add element from the current state of the world.
 java.lang.String getExpCode()
          This function produces Java code that initializes some data structures that will be needed to create the precondition object that implements the precondition of this ForAll delete/add element at run time.
 java.lang.String getInitCode()
          This function produces Java code used to initialize an array of type predicate this ForAll delete/add element will use at run time to represent the atoms that will be deleted/added by this element.
 void setVarCount(int varCount)
          To set the number of variables in this ForAll delete/add element.
 java.lang.String toCode()
          This function produces Java code to create this ForAll delete/add element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

atoms

private Predicate[] atoms
The atoms to be deleted/added.


classCnt

private static int classCnt
The number of objects already instantiated from this class.


cnt

private int cnt
The number of objects already instantiated from this class before this object was instantiated. This is used as a unique identifier for this object to distinguish it from the other objects of this class.


exp

private LogicalExpression exp
The precondtion of the ForAll statement at compile time is represented by this variable.


pre

private Precondition pre
The precondtion of the ForAll statement at run time is represented by this variable.

Constructor Detail

DelAddForAll

public DelAddForAll(LogicalExpression expIn,
                    java.util.Vector<Predicate> atomsIn)
To initialize this ForAll delete/add element at compile time.

Parameters:
expIn - the logical expression to be the precondition of this ForAll delete/add element.
atomsIn - the atoms to be added/deleted as a Vector. Note that we use a Vector rather than an array at compile time because at compile time we do not know how many atoms there will be.

DelAddForAll

public DelAddForAll(Precondition preIn,
                    Predicate[] atomsIn)
To initialize this ForAll delete/add element at run time.

Parameters:
preIn - the logical expression to be the precondition of this ForAll delete/add element.
atomsIn - the atoms to be added/deleted as an array. Note that we use an array rather than a Vector at run time because at run time we know how many atoms there will be.
Method Detail

add

public void add(State s,
                Term[] binding,
                java.util.Vector[] delAddList)
To add the atoms of this ForAll delete/add element to the current state of the world.

Specified by:
add in class DelAddElement
Parameters:
s - the current state of the world.
binding - the binding to be applied before adding the element.
delAddList - an array of size 4 of atoms and protections deleted and added. This is useful when a backtrack happens: Added atoms and protections are retracted, and deleted atoms and protections are added back to change the state of the world to what it was before backtracked decision was made. The 4 elements of the array are the deleted atoms, the added atoms, the deleted protections, and the added protections repectively.

del

public boolean del(State s,
                   Term[] binding,
                   java.util.Vector[] delAddList)
To delete the atoms of this ForAll delete/add element from the current state of the world.

Specified by:
del in class DelAddElement
Parameters:
s - the current state of the world.
binding - the binding to be applied before deleting the element.
delAddList - an array of size 4 of atoms and protections deleted and added. This is useful when a backtrack happens: Added atoms and protections are retracted, and deleted atoms and protections are added back to change the state of the world to what it was before backtracked decision was made. The 4 elements of array are the the deleted atoms, added atoms, deleted protections and added protections in that order.
Returns:
true if the atom(s) associated with this delete/add element were deleted, false otherwise, i.e., when at least one of the atoms to be deleted was protected. If this function returns false, it means the operator has failed and should be backtracked.

getExpCode

public java.lang.String getExpCode()
This function produces Java code that initializes some data structures that will be needed to create the precondition object that implements the precondition of this ForAll delete/add element at run time.

Returns:
the produced code as a String.

getInitCode

public java.lang.String getInitCode()
This function produces Java code used to initialize an array of type predicate this ForAll delete/add element will use at run time to represent the atoms that will be deleted/added by this element. It also produces the code to set the current unifier for the precondition of this element to an empty one (i.e., an array of null elements, because when this precondition is created there is still no binding to be applied to it.

Returns:
the Java code as a String.

setVarCount

public void setVarCount(int varCount)
To set the number of variables in this ForAll delete/add element.

Specified by:
setVarCount in class DelAddElement
Parameters:
varCount - the number of variables.

toCode

public java.lang.String toCode()
This function produces Java code to create this ForAll delete/add element.

Specified by:
toCode in class CompileTimeObject
Returns:
the produced code as a String.