java.lang.Object
org.maxicp.cp.engine.core.AbstractCPConstraint
org.maxicp.cp.engine.constraints.BinPacking
- All Implemented Interfaces:
CPConstraint,ConcreteConstraint<ConcreteCPModel>
The
BinPacking constraint ensures that a set of items with given weights
are packed into bins such that each bin's total weight respects a given capacity constraint.
This constraint is commonly used in Constraint Programming (CP) models to solve bin-packing problems, where a set of weighted items must be assigned to bins while respecting load capacities.
- Author:
- pschaus
-
Constructor Summary
ConstructorsConstructorDescriptionBinPacking(CPIntVar[] x, int[] w, CPIntVar[] load) Constructs aBinPackingconstraint that ensures a set of weighted items are assigned to bins such that the total weight in each bin matches its specified load. -
Method Summary
Modifier and TypeMethodDescriptionvoidpost()Initializes the constraint when it is posted to the solver.Methods inherited from class org.maxicp.cp.engine.core.AbstractCPConstraint
getSolver, isActive, isScheduled, priority, propagate, registerDelta, setActive, setScheduled, updateDeltas
-
Constructor Details
-
BinPacking
Constructs aBinPackingconstraint that ensures a set of weighted items are assigned to bins such that the total weight in each bin matches its specified load.Each item has a predefined weight and must be placed in exactly one bin. The constraint enforces that the sum of item weights assigned to each bin equals the corresponding load variable.
- Parameters:
x- an array ofCPIntVarvariables wherex[i]represents the bin index assigned to itemi.w- an array of integers representing the weights of the items. The weight of itemiisw[i].load- an array ofCPIntVarvariables whereload[b]represents the total weight of binb, which must match the sum of weights of items assigned to that bin.
-
-
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
-