Class ClpVariable

java.lang.Object
org.projog.core.predicate.builtin.clp.ClpVariable
All Implemented Interfaces:
org.projog.clp.Constraint, org.projog.clp.Expression, org.projog.clp.LeafExpression, ArithmeticOperator, Numeric, Term

final class ClpVariable extends Object implements Numeric, org.projog.clp.LeafExpression
A Term that could represent a number of possible numeric values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private ClpVariable
     
    private static final int
     
    private final List<org.projog.clp.Constraint>
     
    private final org.projog.clp.VariableState
     
    private static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
     
    private
    ClpVariable(org.projog.clp.VariableState state, Collection<org.projog.clp.Constraint> rules)
     
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    addConstraint(org.projog.clp.Constraint c)
     
    void
    Reverts this term back to its original state prior to any unifications.
    calculate(Term[] args)
    Returns the result of the calculation using the specified arguments.
     
    copy(Map<Variable,Variable> sharedVariables)
    Returns a copy of this term.
    org.projog.clp.ConstraintResult
    enforce(org.projog.clp.ConstraintStore s)
     
    boolean
     
    Returns an array of this terms's arguments.
    getArgument(int index)
    Returns the term at the specified position in this term's arguments.
    (package private) List<org.projog.clp.Constraint>
     
    double
    Returns the value of this numeric as a double.
    long
    Returns the value of this numeric as a long.
    long
    getMax(org.projog.clp.ReadConstraintStore s)
     
    long
    getMin(org.projog.clp.ReadConstraintStore s)
     
    Returns a string representation of this term.
    int
    Returns the number of arguments in this term.
    (package private) org.projog.clp.VariableState
     
    Returns the current instantiated state of this term.
    Returns the TermType represented by this term.
    int
     
    boolean
    Returns true is this term is immutable.
    org.projog.clp.ConstraintResult
    prevent(org.projog.clp.ConstraintStore s)
     
    org.projog.clp.ConstraintResult
    reify(org.projog.clp.ReadConstraintStore s)
     
    org.projog.clp.LeafExpression
    replace(Function<org.projog.clp.LeafExpression, org.projog.clp.LeafExpression> function)
     
    org.projog.clp.ExpressionResult
    setMax(org.projog.clp.ConstraintStore s, long max)
     
    org.projog.clp.ExpressionResult
    setMin(org.projog.clp.ConstraintStore s, long min)
     
    org.projog.clp.ExpressionResult
    setNot(org.projog.clp.ConstraintStore s, long not)
     
     
    boolean
    Attempts to unify this term to the specified term.
    private static boolean
     
    private boolean
     
    void
    walk(Consumer<org.projog.clp.Expression> r)
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface Term

    getBound
  • Field Details

    • TRUE

      private static final int TRUE
      See Also:
    • FALSE

      private static final int FALSE
      See Also:
    • child

      private ClpVariable child
    • state

      private final org.projog.clp.VariableState state
    • rules

      private final List<org.projog.clp.Constraint> rules
  • Constructor Details

    • ClpVariable

      public ClpVariable()
    • ClpVariable

      private ClpVariable(ClpVariable parent)
    • ClpVariable

      private ClpVariable(org.projog.clp.VariableState state, Collection<org.projog.clp.Constraint> rules)
  • Method Details

    • getConstraints

      List<org.projog.clp.Constraint> getConstraints()
    • addConstraint

      void addConstraint(org.projog.clp.Constraint c)
    • getState

      org.projog.clp.VariableState getState()
    • copy

      public ClpVariable copy()
    • getName

      public String getName()
      Description copied from interface: Term
      Returns a string representation of this term.

      Exact value returned will vary by TermType.

      Specified by:
      getName in interface Term
      Returns:
      a string representation of this term
    • getArgs

      public Term[] getArgs()
      Description copied from interface: Term
      Returns an array of this terms's arguments.

      Note: for performance reasons the array returned is the same array used internally be the term instance so be careful not to alter the array returned as changes will be reflected in the original term.

      Specified by:
      getArgs in interface Term
      Returns:
      array of this terms's arguments
      See Also:
    • getNumberOfArguments

      public int getNumberOfArguments()
      Description copied from interface: Term
      Returns the number of arguments in this term.
      Specified by:
      getNumberOfArguments in interface Term
      Returns:
      number of arguments in this term
    • getArgument

      public Term getArgument(int index)
      Description copied from interface: Term
      Returns the term at the specified position in this term's arguments.
      Specified by:
      getArgument in interface Term
      Parameters:
      index - index of the argument to return
      Returns:
      the term at the specified position in this term's arguments
    • getType

      public TermType getType()
      Description copied from interface: Term
      Returns the TermType represented by this term.
      Specified by:
      getType in interface Term
      Returns:
      the TermType this term represents
    • isImmutable

      public boolean isImmutable()
      Description copied from interface: Term
      Returns true is this term is immutable.

      A term is considered immutable if its value will never change as a result of executing its Term.unify(Term) or Term.backtrack() methods. A term will not be considered immutable if it is a Variable or any of its arguments are not immutable.

      Specified by:
      isImmutable in interface Term
      Returns:
      true is this term is immutable
    • copy

      public ClpVariable copy(Map<Variable,Variable> sharedVariables)
      Description copied from interface: Term
      Returns a copy of this term.

      The returned copy will share any immutable terms contained in this term. The returned copy will contain new instances for any Variables contained in this term. The sharedVariables parameter keeps track of which Variables have already been copied.

      Specified by:
      copy in interface Term
      Parameters:
      sharedVariables - keeps track of which Variables have already been copied (key = original version, value = version used in copy)
      Returns:
      a copy of this term
    • getTerm

      public ClpVariable getTerm()
      Description copied from interface: Term
      Returns the current instantiated state of this term.

      Returns a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.

      Specified by:
      getTerm in interface Term
      Returns:
      a representation of this term with all instantiated Variables replaced with the terms they are instantiated with.
    • unify

      public boolean unify(Term t)
      Description copied from interface: Term
      Attempts to unify this term to the specified term.

      The rules for deciding if two terms are unifiable are as follows:

      • An uninstantiated Variable will unify with any term. As a result the Variable will become instantiated to the other term. The instantiaton will be undone when Term.backtrack() is next called on the Variable
      • Non-variable terms will unify with other terms that are of the same TermType and have the same value. The exact meaning of "having the same value" will vary between term types but will include that the two terms being unified have the same number of arguments and that all of their corresponding arguments unify.
      Note: can leave things in "half-state" on failure as neither List or Predicate backtrack earlier args.
      Specified by:
      unify in interface Term
      Parameters:
      t - the term to unify this term against
      Returns:
      true if the attempt to unify this term to the given term was successful
      See Also:
    • unifyClpVariable

      private static boolean unifyClpVariable(ClpVariable a, Term b)
    • unifyLong

      private boolean unifyLong(Term t)
    • backtrack

      public void backtrack()
      Description copied from interface: Term
      Reverts this term back to its original state prior to any unifications.

      Makes all Variables that this term consists of uninstantiated.

      Specified by:
      backtrack in interface Term
      See Also:
    • getMin

      public long getMin(org.projog.clp.ReadConstraintStore s)
      Specified by:
      getMin in interface org.projog.clp.Constraint
      Specified by:
      getMin in interface org.projog.clp.Expression
    • getMax

      public long getMax(org.projog.clp.ReadConstraintStore s)
      Specified by:
      getMax in interface org.projog.clp.Constraint
      Specified by:
      getMax in interface org.projog.clp.Expression
    • setNot

      public org.projog.clp.ExpressionResult setNot(org.projog.clp.ConstraintStore s, long not)
      Specified by:
      setNot in interface org.projog.clp.Expression
    • setMin

      public org.projog.clp.ExpressionResult setMin(org.projog.clp.ConstraintStore s, long min)
      Specified by:
      setMin in interface org.projog.clp.Constraint
      Specified by:
      setMin in interface org.projog.clp.Expression
    • setMax

      public org.projog.clp.ExpressionResult setMax(org.projog.clp.ConstraintStore s, long max)
      Specified by:
      setMax in interface org.projog.clp.Constraint
      Specified by:
      setMax in interface org.projog.clp.Expression
    • enforce

      public org.projog.clp.ConstraintResult enforce(org.projog.clp.ConstraintStore s)
      Specified by:
      enforce in interface org.projog.clp.Constraint
    • prevent

      public org.projog.clp.ConstraintResult prevent(org.projog.clp.ConstraintStore s)
      Specified by:
      prevent in interface org.projog.clp.Constraint
    • reify

      public org.projog.clp.ConstraintResult reify(org.projog.clp.ReadConstraintStore s)
      Specified by:
      reify in interface org.projog.clp.Constraint
    • walk

      public void walk(Consumer<org.projog.clp.Expression> r)
      Specified by:
      walk in interface org.projog.clp.Constraint
      Specified by:
      walk in interface org.projog.clp.Expression
    • replace

      public org.projog.clp.LeafExpression replace(Function<org.projog.clp.LeafExpression, org.projog.clp.LeafExpression> function)
      Specified by:
      replace in interface org.projog.clp.Constraint
      Specified by:
      replace in interface org.projog.clp.Expression
      Specified by:
      replace in interface org.projog.clp.LeafExpression
    • calculate

      public Numeric calculate(Term[] args)
      Description copied from interface: ArithmeticOperator
      Returns the result of the calculation using the specified arguments.
      Specified by:
      calculate in interface ArithmeticOperator
      Parameters:
      args - the arguments to use in the calculation
      Returns:
      the result of the calculation using the specified arguments
    • getLong

      public long getLong()
      Description copied from interface: Numeric
      Returns the value of this numeric as a long.
      Specified by:
      getLong in interface Numeric
      Returns:
      the value of this numeric as a long
    • getDouble

      public double getDouble()
      Description copied from interface: Numeric
      Returns the value of this numeric as a double.
      Specified by:
      getDouble in interface Numeric
      Returns:
      the value of this numeric as a double
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object