Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I In this homework, you will implement a Python script that solves the multiple knapsack problem using CPLEX. The multiple knapsack problem is defined as
I
In this homework, you will implement a Python script that solves the
multiple knapsack problem using CPLEX. The multiple knapsack problem
is defined as follows: Given a set of N items and a set of M knapsacks
M N with
wj weight of item j
vj value of item j
Ci capacity of knapsack i
select M disjoint subsets of items so that the total profit of the selected items
is a maximum, and each subset can be assigned to a different knapsack whose
capacity is no less than the total weight of items in the subset. Formally,
maximize z
X
M
i
X
N
j
vjxij
subject to: X
N
j
wjxij Ci i M
X
M
i
xij j N
xij in i M j N
where
xij
if a item j is assigned to knapsack i
otherwise.
When M the multiple knapsack problem reduces to the standard knapsack problem.
This problem will be represented using three txt files, namely, weights.txt
values.txt and capacities.txt The first file contains the item weights
ie wj in a single row, and it is composed of the following line for an example problem with five items N :
weights.txt
The second file contains the item values ie vj in a single row, and it
is composed of the following line for the example problem with five items
N :
values.txt
The third file contains the knapsack capacities ie Ci in a single row,
and it is composed of the following line for the example problem with two
knapsacks M :
capacities.txt
The optimum solution of the example problem is as follows:
x
x
x
x
x
x
x
x
x
x
Implement your algorithm to solve the multiple knapsack problem in a
single interactive Python notebook using Azure Lab Services. Your notebook
should include at least the following function definition that takes the file
paths of three input files as parameters and returns the solution found.
def multipleknapsackproblemweightsfile, valuesfile, capacitiesfile:
# your implementation starts below
# your implementation ends above
returnXstar
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started