Package org.jacop.constraints
Class SumWeight
- java.lang.Object
-
- org.jacop.constraints.DecomposedConstraint<Constraint>
-
- org.jacop.constraints.Constraint
-
- org.jacop.constraints.SumWeight
-
- All Implemented Interfaces:
RemoveLevelLate
,SatisfiedPresent
,UsesQueueVariable
public class SumWeight extends Constraint implements UsesQueueVariable, SatisfiedPresent, RemoveLevelLate
SumWeight constraint implements the weighted summation over several variables . It provides the weighted sum from all variables on the list. The weights are integers.Use when number of variables is greater than 15, otherwise use LinearInt.
- Version:
- 3.1
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
backtrackHasOccured
protected long
equalTo
It specifies value to which SumWeight is equal to.(package private) static java.util.concurrent.atomic.AtomicInteger
idNumber
protected IntVar[]
list
It specifies a list of variables being summed.private long
lMax
private long[]
lMaxArray
private long
lMin
private long[]
lMinArray
private TimeStamp<java.lang.Integer>
nextGroundedPosition
The position for the next grounded variable.private java.util.Map<Var,java.lang.Integer>
positionMaping
private TimeStamp<java.lang.Long>
sumGrounded
The sum of grounded variables.(package private) java.util.LinkedHashSet<IntVar>
variableQueue
protected long[]
weights
It specifies a list of weights associated with the variables being summed.-
Fields inherited from class org.jacop.constraints.Constraint
afcWeight, atomicExecution, consistencyPruningEvents, constraintScope, earlyTerminationOK, increaseWeight, numberId, scope, trace, watchedVariableGrounded
-
Fields inherited from class org.jacop.constraints.DecomposedConstraint
queueIndex
-
-
Constructor Summary
Constructors Modifier Constructor Description SumWeight(java.util.List<? extends IntVar> variables, java.util.List<java.lang.Integer> weights, IntVar sum)
It constructs the constraint SumWeight.SumWeight(IntVar[] list, int[] weights, int equalTo)
SumWeight(IntVar[] list, int[] weights, IntVar sum)
private
SumWeight(IntVar[] list, int[] weights, IntVar sum, int equalTo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
checkForOverflow()
void
consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains.private long
divRoundDown(long a, long b)
private long
divRoundUp(long a, long b)
int
getDefaultConsistencyPruningEvent()
void
impose(Store store)
It imposes the constraint in a given store.void
queueVariable(int level, Var var)
This is a function called to indicate which variable in a scope of constraint has changed.void
removeLevelLate(int level)
This function is called in case of the backtrack.boolean
satisfied()
It checks if the constraint is satisfied.java.lang.String
toString()
It produces a string representation of a constraint state.private void
treatChangedVariables()
-
Methods inherited from class org.jacop.constraints.Constraint
afc, arguments, cleanAfterFailure, decompose, getConsistencyPruningEvent, getGuideConstraint, getGuideValue, getGuideVariable, grounded, grounded, id, impose, imposeDecomposition, increaseWeight, intArrayToString, long2int, numberArgs, removeConstraint, requiresMonotonicity, setConsistencyPruningEvent, setConstraintScope, setScope, setScope, setScope, setScope, setScope, setWatchedVariableGrounded, supplyGuideFeedback, toInt, toInt, updateAFC, watchedVariableGrounded
-
Methods inherited from class org.jacop.constraints.DecomposedConstraint
auxiliaryVariables, checkInput, checkInput, checkInputForDuplication, checkInputForDuplicationSkipSingletons, checkInputForNullness, checkInputForNullness, checkInputForNullness, derivative, getDubletonsSkipSingletons, imposeDecomposition
-
-
-
-
Field Detail
-
idNumber
static final java.util.concurrent.atomic.AtomicInteger idNumber
-
list
protected final IntVar[] list
It specifies a list of variables being summed.
-
weights
protected final long[] weights
It specifies a list of weights associated with the variables being summed.
-
equalTo
protected final long equalTo
It specifies value to which SumWeight is equal to.
-
sumGrounded
private TimeStamp<java.lang.Long> sumGrounded
The sum of grounded variables.
-
nextGroundedPosition
private TimeStamp<java.lang.Integer> nextGroundedPosition
The position for the next grounded variable.
-
variableQueue
java.util.LinkedHashSet<IntVar> variableQueue
-
lMin
private long lMin
-
lMax
private long lMax
-
lMinArray
private long[] lMinArray
-
lMaxArray
private long[] lMaxArray
-
positionMaping
private java.util.Map<Var,java.lang.Integer> positionMaping
-
backtrackHasOccured
private boolean backtrackHasOccured
-
-
Constructor Detail
-
SumWeight
public SumWeight(IntVar[] list, int[] weights, IntVar sum)
- Parameters:
list
- the list of varibalesweights
- the list of weightssum
- the resulting sum
-
SumWeight
public SumWeight(IntVar[] list, int[] weights, int equalTo)
- Parameters:
list
- the list of varibalesweights
- the list of weightsequalTo
- the value to which SumWeight is equal to.
-
SumWeight
public SumWeight(java.util.List<? extends IntVar> variables, java.util.List<java.lang.Integer> weights, IntVar sum)
It constructs the constraint SumWeight.- Parameters:
variables
- variables which are being multiplied by weights.weights
- weight for each variable.sum
- variable containing the sum of weighted variables.
-
-
Method Detail
-
removeLevelLate
public void removeLevelLate(int level)
Description copied from interface:RemoveLevelLate
This function is called in case of the backtrack. It is called after all timestamps, variables, mutablevariables have reverted to their values *after* removing the level.- Specified by:
removeLevelLate
in interfaceRemoveLevelLate
- Parameters:
level
- the level which is being removed.
-
consistency
public void consistency(Store store)
Description copied from class:Constraint
It is a (most probably incomplete) consistency function which removes the values from variables domains. Only values which do not have any support in a solution space are removed.- Specified by:
consistency
in classConstraint
- Parameters:
store
- constraint store within which the constraint consistency is being checked.
-
divRoundDown
private long divRoundDown(long a, long b)
-
divRoundUp
private long divRoundUp(long a, long b)
-
getDefaultConsistencyPruningEvent
public int getDefaultConsistencyPruningEvent()
- Specified by:
getDefaultConsistencyPruningEvent
in classConstraint
-
impose
public void impose(Store store)
Description copied from class:Constraint
It imposes the constraint in a given store.- Overrides:
impose
in classConstraint
- Parameters:
store
- the constraint store to which the constraint is imposed to.
-
queueVariable
public void queueVariable(int level, Var var)
Description copied from class:Constraint
This is a function called to indicate which variable in a scope of constraint has changed. It also indicates a store level at which the change has occurred.- Overrides:
queueVariable
in classConstraint
- Parameters:
level
- the level of the store at which the change has occurred.var
- variable which has changed.
-
treatChangedVariables
private void treatChangedVariables()
-
satisfied
public boolean satisfied()
Description copied from interface:SatisfiedPresent
It checks if the constraint is satisfied. It can return false even if constraint is satisfied but not all variables in its scope are grounded. It needs to return true if all variables in its scope are grounded and constraint is satisfied.Implementations of this interface for constraints that are not PrimitiveConstraint may require constraint imposition and consistency check as a requirement to work correctly.
- Specified by:
satisfied
in interfaceSatisfiedPresent
- Returns:
- true if constraint is possible to verify that it is satisfied.
-
checkForOverflow
void checkForOverflow()
-
toString
public java.lang.String toString()
Description copied from class:Constraint
It produces a string representation of a constraint state.- Overrides:
toString
in classConstraint
-
-