java.lang.Object
org.maxicp.cp.engine.core.AbstractCPConstraint
org.maxicp.cp.engine.constraints.BinaryKnapsack
- All Implemented Interfaces:
CPConstraint,ConcreteConstraint<ConcreteCPModel>
A Binary Knapsack constraint ensures that the total load
is equal to the sum of the weights of the selected items.
This constraint models
load = sum_i (b[i] * weights[i])
where:
b[i]is a binary decision variable indicating whether itemiis selected (1) or not (0).weights[i]represents the weight of itemi.loadis an integer variable representing the total weight of selected items.
- Author:
- pschaus
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryKnapsack(CPBoolVar[] b, int[] weights, int load) Constraint: load is the sum of the weights of items selected in to the knapsack.BinaryKnapsack(CPBoolVar[] b, int[] weights, int load, int n) BinaryKnapsack(CPBoolVar[] b, int[] weights, CPIntVar load) A Binary Knapsack constraint ensures that the total load is equal to the sum of the weights of the selected items.BinaryKnapsack(CPBoolVar[] b, int[] weights, CPIntVar load, int n) -
Method Summary
Methods inherited from class org.maxicp.cp.engine.core.AbstractCPConstraint
getSolver, isActive, isScheduled, priority, registerDelta, setActive, setScheduled, updateDeltas
-
Constructor Details
-
BinaryKnapsack
-
BinaryKnapsack
-
BinaryKnapsack
A Binary Knapsack constraint ensures that the total load is equal to the sum of the weights of the selected items.- Parameters:
b- an array ofCPBoolVarvariables whereb[i]is 1 if the item is selected, otherwise 0.weights- an array of non-negative integers representing the weights of the items. Must have the same length asb.load- aCPIntVarvariable representing the total weight of selected items in the knapsack.
-
BinaryKnapsack
Constraint: load is the sum of the weights of items selected in to the knapsack.
load = sum_i b[i]*weights[i]
Available propagation strength are Weak and Strong (the default)- Parameters:
b-weights- a vector of non-negative integers of the same length as bload-
-
-
Method Details
-
post
public void post()Description copied from interface:CPConstraintInitializes the constraint when it is posted to the solver.- Specified by:
postin interfaceCPConstraint- Overrides:
postin classAbstractCPConstraint
-
propagate
public void propagate()Description copied from interface:CPConstraintPropagates the constraint.- Specified by:
propagatein interfaceCPConstraint- Overrides:
propagatein classAbstractCPConstraint
-