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 java.lang.Object implements Numeric, org.projog.clp.LeafExpression
ATermthat could represent a number of possible numeric values.
-
-
Constructor Summary
Constructors Modifier Constructor Description ClpVariable()privateClpVariable(org.projog.clp.VariableState state, java.util.Collection<org.projog.clp.Constraint> rules)privateClpVariable(ClpVariable parent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddConstraint(org.projog.clp.Constraint c)voidbacktrack()Reverts this term back to its original state prior to any unifications.Numericcalculate(Term[] args)Returns the result of the calculation using the specified arguments.ClpVariablecopy()ClpVariablecopy(java.util.Map<Variable,Variable> sharedVariables)Returns a copy of this term.org.projog.clp.ConstraintResultenforce(org.projog.clp.ConstraintStore s)booleanequals(java.lang.Object o)Term[]getArgs()Returns an array of this terms's arguments.TermgetArgument(int index)Returns the term at the specified position in this term's arguments.(package private) java.util.List<org.projog.clp.Constraint>getConstraints()doublegetDouble()Returns the value of this numeric as adouble.longgetLong()Returns the value of this numeric as along.longgetMax(org.projog.clp.ReadConstraintStore s)longgetMin(org.projog.clp.ReadConstraintStore s)java.lang.StringgetName()Returns a string representation of this term.intgetNumberOfArguments()Returns the number of arguments in this term.(package private) org.projog.clp.VariableStategetState()ClpVariablegetTerm()Returns the current instantiated state of this term.TermTypegetType()Returns theTermTyperepresented by this term.inthashCode()booleanisImmutable()Returnstrueis this term is immutable.org.projog.clp.ConstraintResultprevent(org.projog.clp.ConstraintStore s)org.projog.clp.ConstraintResultreify(org.projog.clp.ReadConstraintStore s)org.projog.clp.LeafExpressionreplace(java.util.function.Function<org.projog.clp.LeafExpression,org.projog.clp.LeafExpression> function)org.projog.clp.ExpressionResultsetMax(org.projog.clp.ConstraintStore s, long max)org.projog.clp.ExpressionResultsetMin(org.projog.clp.ConstraintStore s, long min)org.projog.clp.ExpressionResultsetNot(org.projog.clp.ConstraintStore s, long not)java.lang.StringtoString()booleanunify(Term t)Attempts to unify this term to the specified term.private static booleanunifyClpVariable(ClpVariable a, Term b)private booleanunifyLong(Term t)voidwalk(java.util.function.Consumer<org.projog.clp.Expression> r)
-
-
-
Field Detail
-
TRUE
private static final int TRUE
- See Also:
- Constant Field Values
-
FALSE
private static final int FALSE
- See Also:
- Constant Field Values
-
child
private ClpVariable child
-
state
private final org.projog.clp.VariableState state
-
rules
private final java.util.List<org.projog.clp.Constraint> rules
-
-
Constructor Detail
-
ClpVariable
public ClpVariable()
-
ClpVariable
private ClpVariable(ClpVariable parent)
-
ClpVariable
private ClpVariable(org.projog.clp.VariableState state, java.util.Collection<org.projog.clp.Constraint> rules)
-
-
Method Detail
-
getConstraints
java.util.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 java.lang.String getName()
Description copied from interface:TermReturns a string representation of this term.Exact value returned will vary by
TermType.
-
getArgs
public Term[] getArgs()
Description copied from interface:TermReturns 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:
getArgsin interfaceTerm- Returns:
- array of this terms's arguments
- See Also:
Term.getArgument(int)
-
getNumberOfArguments
public int getNumberOfArguments()
Description copied from interface:TermReturns the number of arguments in this term.- Specified by:
getNumberOfArgumentsin interfaceTerm- Returns:
- number of arguments in this term
-
getArgument
public Term getArgument(int index)
Description copied from interface:TermReturns the term at the specified position in this term's arguments.- Specified by:
getArgumentin interfaceTerm- 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:TermReturns theTermTyperepresented by this term.
-
isImmutable
public boolean isImmutable()
Description copied from interface:TermReturnstrueis this term is immutable.A term is considered immutable if its value will never change as a result of executing its
Term.unify(Term)orTerm.backtrack()methods. A term will not be considered immutable if it is aVariableor any of its arguments are not immutable.- Specified by:
isImmutablein interfaceTerm- Returns:
trueis this term is immutable
-
copy
public ClpVariable copy(java.util.Map<Variable,Variable> sharedVariables)
Description copied from interface:Term
-
getTerm
public ClpVariable getTerm()
Description copied from interface:TermReturns 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.
-
unify
public boolean unify(Term t)
Description copied from interface:TermAttempts to unify this term to the specified term.The rules for deciding if two terms are unifiable are as follows:
- An uninstantiated
Variablewill unify with any term. As a result theVariablewill become instantiated to the other term. The instantiaton will be undone whenTerm.backtrack()is next called on theVariable - Non-variable terms will unify with other terms that are of the same
TermTypeand 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.
- Specified by:
unifyin interfaceTerm- Parameters:
t- the term to unify this term against- Returns:
trueif the attempt to unify this term to the given term was successful- See Also:
Term.backtrack()
- An uninstantiated
-
unifyClpVariable
private static boolean unifyClpVariable(ClpVariable a, Term b)
-
unifyLong
private boolean unifyLong(Term t)
-
backtrack
public void backtrack()
Description copied from interface:TermReverts this term back to its original state prior to any unifications.Makes all
Variables that this term consists of uninstantiated.- Specified by:
backtrackin interfaceTerm- See Also:
Term.unify(Term)
-
getMin
public long getMin(org.projog.clp.ReadConstraintStore s)
- Specified by:
getMinin interfaceorg.projog.clp.Constraint- Specified by:
getMinin interfaceorg.projog.clp.Expression
-
getMax
public long getMax(org.projog.clp.ReadConstraintStore s)
- Specified by:
getMaxin interfaceorg.projog.clp.Constraint- Specified by:
getMaxin interfaceorg.projog.clp.Expression
-
setNot
public org.projog.clp.ExpressionResult setNot(org.projog.clp.ConstraintStore s, long not)- Specified by:
setNotin interfaceorg.projog.clp.Expression
-
setMin
public org.projog.clp.ExpressionResult setMin(org.projog.clp.ConstraintStore s, long min)- Specified by:
setMinin interfaceorg.projog.clp.Constraint- Specified by:
setMinin interfaceorg.projog.clp.Expression
-
setMax
public org.projog.clp.ExpressionResult setMax(org.projog.clp.ConstraintStore s, long max)- Specified by:
setMaxin interfaceorg.projog.clp.Constraint- Specified by:
setMaxin interfaceorg.projog.clp.Expression
-
enforce
public org.projog.clp.ConstraintResult enforce(org.projog.clp.ConstraintStore s)
- Specified by:
enforcein interfaceorg.projog.clp.Constraint
-
prevent
public org.projog.clp.ConstraintResult prevent(org.projog.clp.ConstraintStore s)
- Specified by:
preventin interfaceorg.projog.clp.Constraint
-
reify
public org.projog.clp.ConstraintResult reify(org.projog.clp.ReadConstraintStore s)
- Specified by:
reifyin interfaceorg.projog.clp.Constraint
-
walk
public void walk(java.util.function.Consumer<org.projog.clp.Expression> r)
- Specified by:
walkin interfaceorg.projog.clp.Constraint- Specified by:
walkin interfaceorg.projog.clp.Expression
-
replace
public org.projog.clp.LeafExpression replace(java.util.function.Function<org.projog.clp.LeafExpression,org.projog.clp.LeafExpression> function)
- Specified by:
replacein interfaceorg.projog.clp.Constraint- Specified by:
replacein interfaceorg.projog.clp.Expression- Specified by:
replacein interfaceorg.projog.clp.LeafExpression
-
calculate
public Numeric calculate(Term[] args)
Description copied from interface:ArithmeticOperatorReturns the result of the calculation using the specified arguments.- Specified by:
calculatein interfaceArithmeticOperator- 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:NumericReturns the value of this numeric as along.
-
getDouble
public double getDouble()
Description copied from interface:NumericReturns the value of this numeric as adouble.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-