IE507 Lab04
IE507 Lab04
Lab 04 09-September-2020
Instructions:
We will practice modeling optimization problems by loading information from files in this lab. We
will also continue modeling problems with integer variables.
To load directly from a .txt file containing numbers, we will use the numpy.loadtxt() construct.
To know more on the numpy methods to load from files, please check https://numpy.org/doc/
stable/reference/routines.io.html.
To load directly from a file with comma separated values (.csv file), we will use pandas library.
The construct pandas.read csv helps to read contents from a .csv file. Please check https:
//pandas.pydata.org/pandas-docs/stable/getting_started/index.html to know more about
pandas library.
• Similarly, the notebook name for Exercise 2 should be YOURROLLNUMBER IE507 Lab4 Ex2.ipynb,
etc.
• Please post your doubts in MS Teams or Moodle so that TAs can clarify.
There are only 3 exercises in this lab. Try to solve all problems on your own. If you have difficulties,
ask the Instructors or TAs.
Only the questions marked [R] need to be answered in the notebook. You can either print the
answers using print command in your code or you can write the text in a separate text tab. To
add text in your notebook, click +Text. Some questions require you to provide proper explanations;
for such questions, write proper explanations in a text tab.
After completing this lab’s exercises, click File → Download .ipynb and save your files to your local
laptop/desktop. Create a folder with name YOURROLLNUMBER IE507 Lab4 and copy your .ipynb
files to the folder. Then zip the folder to create YOURROLLNUMBER IE507 Lab4.zip. Then upload
only the .zip file to Moodle.
The deadline for today’s lab submission is tomorrow, 10th September 2020, 11 59 PM Indian
Standard Time (IST).
1
IE507, Modeling and Computation Lab
Lab 04 09-September-2020
2
IE507, Modeling and Computation Lab
Lab 04 09-September-2020
Exercise 2: Time taken in MILP. [10 marks] In this exercise we will compare the time taken
to solve LP and MILP. Consider the integer optimization problem
n
X
max cj xj
j=1
n
X
s.t. aij xj ≤ bi , i = 1, . . . , m (MILP)
j=1
xj ∈ {0, 1}, j = 1 . . . , n.
0 ≤ xj ≤ 1, j = 1 . . . , n.
Specific data is available for this problem in Moodle in lab4 ex2 lp ip coef.txt file. It has n = 500
variables and m = 5 constraints. Note that the file is modeled similar to the lab4 practice coef.txt
file used in practice session.
1. Copy the lab4 ex2 lp ip coef.txt file to colab environment.
2. Use numpy.loadtxt to load lab4 ex2 lp ip coef.txt into an appropriate numpy array.
3. [R] Create a pyomo model using the coefficients loaded from the file and solve the MILP
using cbc solver. Report the optimal objective function value (Do not report the values of
variables).
4. [R] How much time does it take to solve the MILP? Suppose you have saved the results of
opt cbc.solve to results, you can use results.solver.time to report time.
5. [R] Solve the LP relaxation (LP obtained by removing integer restrictions on all variables) of
the same problem using cbc solver. Report only the objective function values of the optimal
solution. (You need not report the values of the variables.)
6. [R] How much time does it take to solve the problem? Compare with the results obtained by
solving the MILP.
7. [R] Also report the statistics printed in Branch and Bound section of results for both MILP
and LP.
3
IE507, Modeling and Computation Lab
Lab 04 09-September-2020
Drone Model Carrying Capacity (kgs) Cost (in Crores of rupees) Parking space (sq. m.)
SANKALP 15 4 3
KARTAV 10 3.5 3.25
SAAHAS 20 5 4
VIJAY 10 4 2.75
LAKSHYA 15 4.5 2.5
The IAF wants to have maximum possible carrying capacity. The budget of IAF is limited to 29
crores of rupees. In addition, parking space for drones is limited to 37 sq. m.
1. Create a .csv file containing the data given in the table. Name the file as lab4 ex3.csv. Use
simple and appropriate names for the headers.
2. Copy the file to colab environment.