blog
Class RandomFunction

java.lang.Object
  extended by blog.Function
      extended by blog.RandomFunction
Direct Known Subclasses:
SkolemConstant

public class RandomFunction
extends Function

Represents random functions, whose value for the given tuple of arguments changes from world to world.

See Also:
Function

Nested Class Summary
 
Nested classes/interfaces inherited from class blog.Function
Function.Sig
 
Constructor Summary
RandomFunction(java.lang.String fname, java.util.List arg_types, Type ret_type, DependencyModel depmodel)
           
 
Method Summary
 boolean checkTypesAndScope(Model model)
          Returns true if the dependency statement or interpretation statement for this function (if any) satisfies type and scope constraints.
 int compile(java.util.LinkedHashSet callStack)
          Ensures that this function has a dependency statement, and compiles that dependency statement.
 LogicalVar[] getArgVars()
          Returns the logical variables that stand for the function arguments in this function's dependency model.
 DependencyModel getDepModel()
           
 LogicalVar getTimeVar()
          If this function is indexed by time, returns the variable that stands for its time argument in its dependency model.
 java.lang.Object getValueInContext(java.lang.Object[] args, EvalContext context, boolean stable)
          Returns the value of this function applied to the given tuple of arguments in the given context.
 boolean hasDepModel()
           
 void printDepStatement(java.io.PrintStream s)
          Prints the dependency statement for this function to the given stream.
 RandFuncAppVar rv()
          Returns a basic random variable for this function with no arguments.
 RandFuncAppVar rv(java.lang.Object arg)
          Returns a basic random variable for this function with the given single argument.
 RandFuncAppVar rv(java.lang.Object arg1, java.lang.Object arg2)
          Returns a basic random variable for this function with the given two arguments.
 RandFuncAppVar rvWithArgs(java.lang.Object[] args)
          Returns a basic random variable for this function with the given array of arguments.
 void setArgVars(java.util.List vars)
          Sets the variables that will stand for the function arguments in this function's dependency model.
 void setDepModel(DependencyModel depmodel)
           
 
Methods inherited from class blog.Function
appliesTo, domainIterator, domainIterator, getArgTypes, getCreationIndex, getDefaultValue, getName, getRetType, getSig, getValue, getValue, getValue, getValueSingleArg, isTimeIndexed, overlapsWith, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RandomFunction

public RandomFunction(java.lang.String fname,
                      java.util.List arg_types,
                      Type ret_type,
                      DependencyModel depmodel)
Method Detail

getArgVars

public LogicalVar[] getArgVars()
Returns the logical variables that stand for the function arguments in this function's dependency model.


setArgVars

public void setArgVars(java.util.List vars)
Sets the variables that will stand for the function arguments in this function's dependency model.

Parameters:
vars - List of String objects representing the variables

getTimeVar

public LogicalVar getTimeVar()
If this function is indexed by time, returns the variable that stands for its time argument in its dependency model. Otherwise returns null.

Throws:
java.lang.IllegalStateException - if this function's argument variables have not been set yet.

getDepModel

public DependencyModel getDepModel()

setDepModel

public void setDepModel(DependencyModel depmodel)

hasDepModel

public boolean hasDepModel()

rv

public RandFuncAppVar rv()
Returns a basic random variable for this function with no arguments.


rv

public RandFuncAppVar rv(java.lang.Object arg)
Returns a basic random variable for this function with the given single argument.


rv

public RandFuncAppVar rv(java.lang.Object arg1,
                         java.lang.Object arg2)
Returns a basic random variable for this function with the given two arguments.


rvWithArgs

public RandFuncAppVar rvWithArgs(java.lang.Object[] args)
Returns a basic random variable for this function with the given array of arguments.


checkTypesAndScope

public boolean checkTypesAndScope(Model model)
Description copied from class: Function
Returns true if the dependency statement or interpretation statement for this function (if any) satisfies type and scope constraints. If there is a type or scope error, prints a message to standard error and returns false.

This default implementation just returns true.

Overrides:
checkTypesAndScope in class Function

compile

public int compile(java.util.LinkedHashSet callStack)
Ensures that this function has a dependency statement, and compiles that dependency statement. If this function is in the call stack, does nothing -- recursion among random functions is allowed.

Overrides:
compile in class Function
Parameters:
callStack - Set of objects whose compile methods are parents of this method invocation. Ordered by invocation order. Used to detect cycles.

printDepStatement

public void printDepStatement(java.io.PrintStream s)
Prints the dependency statement for this function to the given stream.


getValueInContext

public java.lang.Object getValueInContext(java.lang.Object[] args,
                                          EvalContext context,
                                          boolean stable)
Description copied from class: Function
Returns the value of this function applied to the given tuple of arguments in the given context. If the partial world in the given context is not complete enough to determine the function value, this method returns null.

Specified by:
getValueInContext in class Function
stable - if true, the caller guarantees that the args array will not be modified