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, we will learn how to build this problem using the nonlinear-program solver. Open the knapsack_nl.py
code file. We have created 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_sampler
function:- Define the sampler to be used. Remember to import any necessary packages.
-
In the
build_nl
function:-
Initialize the NL object called
model
, and import any necessary packages -
Set the objective function in the NL model
-
Add the two constraints to the NL model
-
Released under the Apache License 2.0. See LICENSE file.