JSHOP2
Class State

java.lang.Object
  extended by JSHOP2.State

public class State
extends java.lang.Object

This class is used to represent the current state of the world.

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

Field Summary
private  java.util.Vector<Term>[] atoms
          The atoms in the current state of the world as an array of Vectors.
private  Axiom[][] axioms
          The axioms in the domain description as a two-dimensional array.
private  java.util.Vector<NumberedPredicate>[] protections
          The protections in the current state of the world as an array of Vectors.
 
Constructor Summary
State(int size, Axiom[][] axiomsIn)
          To initialize the state of the world.
 
Method Summary
 boolean add(Predicate p)
          To add a predicate to the current state of the world.
 boolean addProtection(Predicate p)
          To protect a given predicate in the current state of the world.
 void clear()
          To empty the world state.
 int del(Predicate p)
          To delete a predicate from the current state of the world.
 boolean delProtection(Predicate p)
          To unprotect a given predicate.
 java.util.ArrayList<java.lang.String> getState()
          Returns an ArrayList of strings that represents the state.
 boolean isProtected(Predicate p)
          To check if a predicate is protected.
 MyIterator iterator(int head)
          To initialize and return the appropriate iterator when looking for ways to satisfy a given predicate.
 Term[] nextBinding(Predicate p, MyIterator me)
          This function returns the bindings that can satisfy a given precondition one-by-one.
 void print()
          This function is used to print the current state of the world.
 void undo(java.util.Vector[] delAdd)
          This function is used, in case of a backtrack, to undo the changes that were made to the current state of the world because of the backtracked decision.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

atoms

private java.util.Vector<Term>[] atoms
The atoms in the current state of the world as an array of Vectors. The array is indexed by the possible heads (i.e., the constant symbol that comes first) of the possible predicates.


axioms

private Axiom[][] axioms
The axioms in the domain description as a two-dimensional array. The array is indexed first by the head of the predicates each axiom can prove and second by the axioms themselves.


protections

private java.util.Vector<NumberedPredicate>[] protections
The protections in the current state of the world as an array of Vectors. The array is indexed by the heads of protected predicates.

Constructor Detail

State

public State(int size,
             Axiom[][] axiomsIn)
To initialize the state of the world.

Parameters:
size - the number of possible heads of predicates (i.e., the number of constant symbols that can come first in a predicate).
axiomsIn - the axioms in the domain description as a two-dimensional array. The array is indexed first by the head of the predicates each axiom can prove and second by the axioms themselves.
Method Detail

add

public boolean add(Predicate p)
To add a predicate to the current state of the world.

Parameters:
p - the predicate to be added.
Returns:
true if the predicate was added (i.e., it was not already in the current state of the world), false otherwise.

addProtection

public boolean addProtection(Predicate p)
To protect a given predicate in the current state of the world.

Parameters:
p - the predicate to be protected.
Returns:
this function always returns true.

clear

public void clear()
To empty the world state.


del

public int del(Predicate p)
To delete a predicate from the current state of the world.

Parameters:
p - the predicate to be deleted.
Returns:
the index of the predicate that was deleted in the Vector if the predicate was deleted (i.e., it existed in the current state of the world), -1 otherwise. This index is used in case of a backtrack to undo this deletion by inserting the deleted predicate right back where it used to be.

delProtection

public boolean delProtection(Predicate p)
To unprotect a given predicate.

Parameters:
p - the predicate to be unprotected.
Returns:
true if the protected is unprotected successfully, false otherwise (i.e., when the predicate was not protected before).

isProtected

public boolean isProtected(Predicate p)
To check if a predicate is protected.

Parameters:
p - the predicate to be checked.
Returns:
true if the predicate is protected, false otherwise.

iterator

public MyIterator iterator(int head)
To initialize and return the appropriate iterator when looking for ways to satisfy a given predicate.

Parameters:
head - the index of the constant symbol that is the head of the predicate (i.e., that comes first in the predicate).
Returns:
the iterator to be used to find the satisfiers for this predicate.

nextBinding

public Term[] nextBinding(Predicate p,
                          MyIterator me)
This function returns the bindings that can satisfy a given precondition one-by-one.

Parameters:
p - the predicate to be satisfied.
me - the iterator that keeps track of where we are with the satisfiers so that the next time this function is called, we can take off where we stopped last time.
Returns:
the next binding as an array of terms indexed by the indeices of the variable symbols in the given predicate.

print

public void print()
This function is used to print the current state of the world.


getState

public java.util.ArrayList<java.lang.String> getState()
Returns an ArrayList of strings that represents the state. Used in conjunction with JSHOP2GUI (Added 5/28/06)

Returns:
- An ArrayList representing the state

undo

public void undo(java.util.Vector[] delAdd)
This function is used, in case of a backtrack, to undo the changes that were made to the current state of the world because of the backtracked decision.

Parameters:
delAdd - a 4-member array of type Vector. These four members are the deleted atoms, the added atoms, the deleted protections and the added protections respectively.