blog
Class Function

java.lang.Object
  extended by blog.Function
Direct Known Subclasses:
NonRandomFunction, OriginFunction, RandomFunction

public abstract class Function
extends java.lang.Object

Represents a BLOG function. A function is specified by its name, return type, and argument types.


Nested Class Summary
static class Function.Sig
          Nested class representing a function signature, that is, a function name and a tuple of argument types.
 
Constructor Summary
Function(java.lang.String fname, java.util.List argTypeList, Type retType)
           
 
Method Summary
 boolean appliesTo(Type[] types)
          Returns true if this function applies to all tuples of objects with the given types.
 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 is ready to be used by an inference engine.
 java.util.Iterator domainIterator()
          Returns an iterator over the tuples of objects that can serve as arguments to this function.
 java.util.Iterator domainIterator(boolean skipLastArg)
          Returns an iterator over the tuples of objects that can serve as arguments to this function.
 Type[] getArgTypes()
           
 int getCreationIndex()
          Returns an index indicating when this function was declared (or otherwise created).
 java.lang.Object getDefaultValue()
          Returns the value of this function on arguments that are not in its domain.
 java.lang.String getName()
           
 Type getRetType()
           
 Function.Sig getSig()
           
 java.lang.Object getValue(java.lang.Object[] args, PartialWorld w)
          Returns the value of this function applied to the given tuple of arguments in the given partial world.
 java.lang.Object getValue(java.lang.Object arg1, java.lang.Object arg2, PartialWorld w)
          Returns the value of this function applied to the given pair of arguments in the given partial world (this method should be used only for binary functions).
 java.lang.Object getValue(PartialWorld w)
          Returns the value of this function applied to an empty tuple of arguments in the given partial world (this method should be used only for zero-ary functions).
abstract  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.
 java.lang.Object getValueSingleArg(java.lang.Object arg, PartialWorld w)
          Returns the value of this function applied to the given single argument in the given partial world (this method should be used only for unary functions).
 boolean isTimeIndexed()
          Returns true if this function is indexed by time, that is, it has a final argument of type Timestep.
 boolean overlapsWith(Type[] types)
          Returns true if this function could apply to some tuple of non-null objects with the given types.
 java.lang.String toString()
          Returns this function's name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Function

public Function(java.lang.String fname,
                java.util.List argTypeList,
                Type retType)
Method Detail

getName

public java.lang.String getName()

getArgTypes

public Type[] getArgTypes()

getRetType

public Type getRetType()

getSig

public Function.Sig getSig()

appliesTo

public boolean appliesTo(Type[] types)
Returns true if this function applies to all tuples of objects with the given types. This is true if each type in the given tuple is a subtype of the corresponding type in this function's argument type tuple (and the tuples have the same length).


overlapsWith

public boolean overlapsWith(Type[] types)
Returns true if this function could apply to some tuple of non-null objects with the given types. Since we have single inheritance (except for NULL_TYPE), this is true if every type in the given tuple is either a subtype or a supertype of the corresponding type in this function's argument type tuple (and the tuples have the same length).


checkTypesAndScope

public boolean checkTypesAndScope(Model model)
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.


compile

public int compile(java.util.LinkedHashSet callStack)
Ensures that this function is ready to be used by an inference engine. If any errors occur, prints a message to standard error. Returns the number of errors that occurred.

This default implementation just returns 0.

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

getValue

public java.lang.Object getValue(java.lang.Object[] args,
                                 PartialWorld w)
Returns the value of this function applied to the given tuple of arguments in the given partial world. If the given partial world is not complete enough to determine the function value, this method returns null.


getValue

public java.lang.Object getValue(PartialWorld w)
Returns the value of this function applied to an empty tuple of arguments in the given partial world (this method should be used only for zero-ary functions). If the given partial world is not complete enough to determine the function value, this method returns null.


getValueSingleArg

public java.lang.Object getValueSingleArg(java.lang.Object arg,
                                          PartialWorld w)
Returns the value of this function applied to the given single argument in the given partial world (this method should be used only for unary functions). If the given partial world is not complete enough to determine the function value, this method returns null.


getValue

public java.lang.Object getValue(java.lang.Object arg1,
                                 java.lang.Object arg2,
                                 PartialWorld w)
Returns the value of this function applied to the given pair of arguments in the given partial world (this method should be used only for binary functions). If the given partial world is not complete enough to determine the function value, this method returns null.


getValueInContext

public abstract 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. If the partial world in the given context is not complete enough to determine the function value, this method returns null.

Parameters:
stable - if true, the caller guarantees that the args array will not be modified

getDefaultValue

public java.lang.Object getDefaultValue()
Returns the value of this function on arguments that are not in its domain. This is Boolean.FALSE for Boolean functions, and Model.NULL for other functions.


isTimeIndexed

public boolean isTimeIndexed()
Returns true if this function is indexed by time, that is, it has a final argument of type Timestep.


domainIterator

public java.util.Iterator domainIterator()
Returns an iterator over the tuples of objects that can serve as arguments to this function. Raises a fatal error if this would require enumerating a random or infinite set.

Returns:
Iterator over Lists

domainIterator

public java.util.Iterator domainIterator(boolean skipLastArg)
Returns an iterator over the tuples of objects that can serve as arguments to this function. Raises a fatal error if this would require enumerating a random or infinite set.

Parameters:
skipLastArg - if true, exclude the last argument from the tuples (useful for time-indexed functions)
Returns:
Iterator over Lists

getCreationIndex

public int getCreationIndex()
Returns an index indicating when this function was declared (or otherwise created).


toString

public java.lang.String toString()
Returns this function's name.

Overrides:
toString in class java.lang.Object