A collection of
- Objective: Maximize the total value of the container
- Constraint 1: Total weight of the shipped container should not exceed the capacity weight
- Constraint 2: At most two items can be included in the container
This is an example of the knapsack problem. In this exercise, you will build the problem using the Stride hybrid solver. Open the knapsack.py code file. There is an array of binary variable symbols for five items. The value and weight of each item is defined in the values and weights constant symbols. The maximum capacity of the container is set to 10.
You will need to fill in the set_sampler and build_nl functions. Here are the instructions to follow:
-
In the
set_samplerfunction:- Define the sampler to be used. Remember to import the required package.
-
In the
build_nlfunction:-
Initialize the nonlinear object called
model, and import the required package. -
Set the objective function in the nonlinear model.
-
Add the two constraints to the nonlinear model.
-