Module org.maxicp

Class BinaryKnapsack

java.lang.Object
org.maxicp.cp.engine.core.AbstractCPConstraint
org.maxicp.cp.engine.constraints.BinaryKnapsack
All Implemented Interfaces:
CPConstraint, ConcreteConstraint<ConcreteCPModel>

public class BinaryKnapsack extends AbstractCPConstraint
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 item i is selected (1) or not (0).
  • weights[i] represents the weight of item i.
  • load is an integer variable representing the total weight of selected items.
Author:
pschaus
  • Constructor Details

    • BinaryKnapsack

      public BinaryKnapsack(CPBoolVar[] b, int[] weights, CPIntVar load, int n)
    • BinaryKnapsack

      public BinaryKnapsack(CPBoolVar[] b, int[] weights, int load, int n)
    • BinaryKnapsack

      public 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.
      Parameters:
      b - an array of CPBoolVar variables where b[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 as b.
      load - a CPIntVar variable representing the total weight of selected items in the knapsack.
    • BinaryKnapsack

      public BinaryKnapsack(CPBoolVar[] b, int[] weights, int load)
      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 b
      load -
  • Method Details