blog
Class DefaultEvalContext

java.lang.Object
  extended by blog.DefaultEvalContext
All Implemented Interfaces:
EvalContext
Direct Known Subclasses:
ParentRecEvalContext

public class DefaultEvalContext
extends java.lang.Object
implements EvalContext

Basic implementation of the EvalContext interface. When the underlying partial world is not complete enough to support a call to getValue or getSatisfiers, this implementation either prints an error message and exits the program, or just returns null. Returning null is the default behavior; the fatal error behavior can be obtained by constructing a DefaultEvalContext with the errorIfUndet flag set to true.


Field Summary
protected  boolean errorIfUndet
           
protected  PartialWorld world
           
 
Constructor Summary
DefaultEvalContext(PartialWorld world)
          Creates a new evaluation context using the given partial world.
DefaultEvalContext(PartialWorld world, boolean errorIfUndet)
          Creates a new evaluation context using the given partial world.
 
Method Summary
 void assign(LogicalVar var, java.lang.Object value)
          Assigns the given value to the given logical variable, overwriting any previous value.
 void assignTuple(LogicalVar[] vars, java.lang.Object[] values)
          Assigns values to a tuple of logical variables.
 java.lang.String getAssignmentStr()
          Returns a string describing the assignment of values to variables in this context.
 java.lang.Object getLogicalVarValue(LogicalVar var)
          Returns the value of the given logical variable in this context, or null if the given logical variable has no assigned value.
 java.util.Set getLogicalVarValues()
          Returns the set of objects that are the value of some logical variable in this context.
 NumberVar getPOPAppSatisfied(java.lang.Object obj)
          Returns the NumberVar (i.e., POP and generating objects) such that the given object satisfies that POP applied to those generating objects in this world.
 ObjectSet getSatisfiers(NumberVar popApp)
          Returns the set of objects that satisfy the given POP in this world.
 java.lang.Object getValue(BasicVar var)
          Returns the value of the given basic random variable in this partial world, or null if the given variable is not instantiated.
protected  void handleMissingVar(BayesNetVar var)
          Handle the situation where an access method needs the value of the given variable, but it is not instantiated.
 java.lang.Boolean objectExists(java.lang.Object obj)
          Returns Boolean.TRUE if obj exists in all worlds consistent with this context's partial world.
 void popEvaluee()
          Pops the top object from the stack of objects being evaluated.
 void printEvalTrace(java.io.PrintStream s)
          Prints the sequence of objects being evaluated, in the order they were added to the stack, to the given stream.
 void pushEvaluee(java.lang.Object evaluee)
          Pushes the given object onto the stack of objects being evaluated.
 void unassign(LogicalVar var)
          Erases any value currently assigned to the given logical variable.
 void unassignTuple(LogicalVar[] vars)
          Erases any values currently assigned to any of the given logical variables.
 boolean usesIdentifiers(Type type)
          Returns true if the world that underlies this context uses object identifiers for the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

world

protected PartialWorld world

errorIfUndet

protected boolean errorIfUndet
Constructor Detail

DefaultEvalContext

public DefaultEvalContext(PartialWorld world)
Creates a new evaluation context using the given partial world. This DefaultEvalContext instance will return null from access methods if the world is not complete enough to determine the correct value.


DefaultEvalContext

public DefaultEvalContext(PartialWorld world,
                          boolean errorIfUndet)
Creates a new evaluation context using the given partial world. If the errorIfUndet flag is true, the access methods on this instance will print error messages and exit the program if the world is not complete enough to determine the correct return value.

Method Detail

getValue

public java.lang.Object getValue(BasicVar var)
Description copied from interface: EvalContext
Returns the value of the given basic random variable in this partial world, or null if the given variable is not instantiated.

Specified by:
getValue in interface EvalContext

getSatisfiers

public ObjectSet getSatisfiers(NumberVar popApp)
Description copied from interface: EvalContext
Returns the set of objects that satisfy the given POP in this world. The objects may be represented as actual objects or identifiers, depending on the way the underlying PartialWorld implementation handles objects of the relevant type. A null return value indicates that the relevant number variable is not instantiated.

The set returned by this method will remain correct if new basic random variables are instantiated. It may not remain correct if new identifiers are added or already-instantiated random variables are changed.

Specified by:
getSatisfiers in interface EvalContext

getPOPAppSatisfied

public NumberVar getPOPAppSatisfied(java.lang.Object obj)
Description copied from interface: EvalContext
Returns the NumberVar (i.e., POP and generating objects) such that the given object satisfies that POP applied to those generating objects in this world. Returns null if the given object does not satisfy any POP application.

Specified by:
getPOPAppSatisfied in interface EvalContext

usesIdentifiers

public boolean usesIdentifiers(Type type)
Description copied from interface: EvalContext
Returns true if the world that underlies this context uses object identifiers for the given type.

Specified by:
usesIdentifiers in interface EvalContext

objectExists

public java.lang.Boolean objectExists(java.lang.Object obj)
Description copied from interface: EvalContext
Returns Boolean.TRUE if obj exists in all worlds consistent with this context's partial world. This is true if obj is a guaranteed object, a concrete non-guaranteed object whose number variable is instantiated to a sufficiently large value, or an object identifier. Returns Boolean.FALSE if obj is a concrete non-guaranteed object whose number variable is instantiated to a value that is too small. If neither of the above cases holds, then this method returns null.

Specified by:
objectExists in interface EvalContext

getLogicalVarValue

public java.lang.Object getLogicalVarValue(LogicalVar var)
Description copied from interface: EvalContext
Returns the value of the given logical variable in this context, or null if the given logical variable has no assigned value.

Specified by:
getLogicalVarValue in interface EvalContext

getLogicalVarValues

public java.util.Set getLogicalVarValues()
Description copied from interface: EvalContext
Returns the set of objects that are the value of some logical variable in this context.

Specified by:
getLogicalVarValues in interface EvalContext
Returns:
unmodifiable Set of Object

getAssignmentStr

public java.lang.String getAssignmentStr()
Description copied from interface: EvalContext
Returns a string describing the assignment of values to variables in this context.

Specified by:
getAssignmentStr in interface EvalContext

assign

public void assign(LogicalVar var,
                   java.lang.Object value)
Description copied from interface: EvalContext
Assigns the given value to the given logical variable, overwriting any previous value.

Specified by:
assign in interface EvalContext

assignTuple

public void assignTuple(LogicalVar[] vars,
                        java.lang.Object[] values)
Description copied from interface: EvalContext
Assigns values to a tuple of logical variables.

Specified by:
assignTuple in interface EvalContext
Parameters:
vars - array of LogicalVar objects
values - array of Objects, in one-to-one correspondence with the elements of vars, representing values for those variables

unassign

public void unassign(LogicalVar var)
Description copied from interface: EvalContext
Erases any value currently assigned to the given logical variable.

Specified by:
unassign in interface EvalContext

unassignTuple

public void unassignTuple(LogicalVar[] vars)
Description copied from interface: EvalContext
Erases any values currently assigned to any of the given logical variables.

Specified by:
unassignTuple in interface EvalContext

pushEvaluee

public void pushEvaluee(java.lang.Object evaluee)
Pushes the given object onto the stack of objects being evaluated. This stack is maintained purely so that the EvalContext can print more informative error messages.

Specified by:
pushEvaluee in interface EvalContext

popEvaluee

public void popEvaluee()
Pops the top object from the stack of objects being evaluated.

Specified by:
popEvaluee in interface EvalContext
Throws:
java.lang.IllegalStateException - if the stack of objects being evaluated is empty

printEvalTrace

public void printEvalTrace(java.io.PrintStream s)
Prints the sequence of objects being evaluated, in the order they were added to the stack, to the given stream.

Specified by:
printEvalTrace in interface EvalContext

handleMissingVar

protected void handleMissingVar(BayesNetVar var)
Handle the situation where an access method needs the value of the given variable, but it is not instantiated. This method either prints an error message and exits the program, or does nothing, depending on the value of the errorIfUndet field.