Starting from:

$30

IE507-Lab5 Solved

Instructions:

We will practice modeling a transportation problem and a facility assignment problem in this lab. These problems can be formulated as appropriate optimization problems with an associated objective function and constraints. Two-dimensional decision variables are useful in these problems, and we will focus on using such two-dimensional variables in model building using pyomo.

We will continue to model problems by loading information from files in this lab. We will also continue modeling problems with integer variables, wherever required.

Recall, to load directly from a file with comma separated values (.csv file), we used 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.

In this lab, accessing the data frame using iloc is discussed in detail. For more details on this iloc function, please see https://pandas.pydata.org/pandas-docs/stable/reference/api/ pandas.DataFrame.iloc.html

Please follow the instructions given below:

•    Please use different notebooks for solving different problems.

•    The notebook name for Exercise 1 should be YOURROLLNUMBER IE507 Lab5  Ex1.ipynb.

•    Similarly, the notebook name for Exercise 2 should be YOURROLLNUMBER IE507 Lab5  Ex2.ipynb.

•    Please post your doubts in MS Teams or Moodle so that TAs can clarify.

For more details on pyomo, please consult https://pyomo.readthedocs.io/en/stable/index. html.

There are only 2 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 Lab5 and copy your .ipynb files to the folder. Also copy the .csv files to the folder. Then zip the folder to create YOURROLLNUMBER  IE507 Lab5.zip. Then upload only the .zip file to Moodle.

The deadline for today’s lab submission is tomorrow, 17th September 2020, 11 59 PM Indian Standard Time (IST).

Exercise 1: Transportation Problem [15 marks]

A customer has contacted Jai Logistics for transporting air-conditioner units (ACUs) from warehouses to markets. There are eight warehouses, each of which has some truck-loads of ACUs in stock. These ACUs must be transported to eight markets for satisfying the demand. You are interning at Jai Logistics and you are given the task of finding out how many ACUs must be transported from each warehouse to each market.

1.    [R] Let C[w,m] be the cost of transporting one truck-load of ACUs from w to m. Write a general optimization problem to minimize the total transportation cost. Use appropriate notations and define appropriate sets to be used in the optimization problem.

2.    Use the costs, demands and available stocks from Table 1 to create a .csv file, similar to that used in the practice exercise. You can use the transport.txt file uploaded in Moodle to create the .csv file. Name the file as lab5 ex1.csv. Use simple and appropriate names for the headers.

3.    Copy the file to colab environment.

4.    Use pandas to load the .csv file contents.

5.    Create a model using pyomo to solve your optimization problem. Use the loaded contents of .csv file to create your model. Use iloc function of pandas library to access the data frame contents obtained from the .csv file.

6.    Use cbc solver to solve your optimization problem. In your code, remember to specify which variables are integers.

Table 1: Cost of Transporting a Truck-load of AC Units

 
 
 
 
Markets
 
 
 
 
Warehouses
Indore
Jodhpur
Vellore
Kanpur
Hyderabad
Patna
Raipur
Cuttack
Avail. Stock
Ahmedabad
427
617
1270
982
915
943
974
1265
100
Bengaluru
1179
1623
372
2072
257
1373
1052
959
250
Chennai
1409
1823
59
2127
358
1422
1304
811
200
Delhi
1123
533
2265
467
1896
941
1232
1348
200
Kolkata
1712
2079
1830
1499
1929
439
691
128
150
Lucknow
886
760
1965
83
1759
395
795
1332
90
Mumbai
546
817
1045
1232
905
1211
1187
1487
290
Nagpur
495
1062
1113
1121
802
1125
474
801
200
Demand
75
300
250
200
400
100
50
70
 
7.    [R] Report the number of truck-loads of ACUs that are transported (report only those values that are nonzero) from warehouses to markets. Report the total cost also.

8.    [R] Suppose the Bengaluru-Patna link is disrupted and no transportation is possible on the link. Without changing the pyomo model, how will you solve this problem? You are only allowed to change the .csv file.

9.    [R] Report the new solution value and the nonzero flows in the network.

Exercise 2: Assigning Locations [20 Marks]

Mansarov Constructions Inc. has to build n ∈N different types of factories, one at each of the n locations. The cost of constructing (setup cost) the ith facility at the jth location provided in the Table 2 below. Mansarov Constructions Inc. wants to minimize the sum of the costs of assigning all the facilities to the locations.

Factory
 
 
 
 
 
Location
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
1
19
12
18
19
22
21
17
20
16
15
21
24
2
22
22
19
21
22
24
18
17
21
19
22
23
3
18
23
20
20
21
22
19
18
20
23
19
19
4
18
21
20
18
17
19
24
16
18
16
20
24
5
23
17
16
19
24
21
23
21
20
21
22
21
6
23
20
17
16
20
23
22
25
24
19
17
20
7
22
18
17
15
22
24
23
20
22
19
23
20
8
24
22
21
23
18
17
16
19
24
21
20
23
9
21
20
17
18
16
24
19
17
18
20
21
23
10
19
22
21
24
20
23
19
18
23
24
25
20
11
20
24
22
20
23
19
18
16
22
24
21
24
12
22
23
24
20
21
20
20
19
17
19
20
22
Table 2: Set up cost of factories at different locations

1.       [R] Write a mathematical model to solve the assignment problem explained above. Define all the variables and constraints clearly. Use appropriate notations and define appropriate sets to be used in your optimization problem.

2.       Construct a pyomo model for this problem for a general n. You can assume that the cost matrix is given as data from a txt file and can be loaded as a numpy array.

3.       Use the data in Table 2 to make a .txt file for your model. You can use the setupcosts.txt file uploaded in Moodle to create the .txt file. Name the file as lab5  ex2.txt.

4.       Copy the file to colab environment.

5.       Use numpy.loadtxt to load the data from lab5 ex2.txt file into a numpy array.

6.       Adapt the general pyomo model you created, to use the data loaded from the lab5  ex2.txt file.

7.       Use cbc solver to solve your optimization problem. In your code, remember to specify which variables are integers.

8.       [R] Solve the problem and report which facility must be opened at each location.

9.       [R] Now change the integer variables in your model to continuous variables, and re-solve the problem. Report the solution (only the non-zero values of the solution).

10.   [R] Are the optimal costs for both problems same? Are the values of the variables still integer-valued? If yes, explain why.

11.   Will the solution to the continuous problem become fractional (non-integer) if the costs are changed to non-integer values? Try changing the costs to different values and test whether the solution to the LP becomes fractional for any of them.

12.   [R] Now suppose that, due to some reason, facility 1 cannot be assigned to location 4, facility 11 cannot be assigned to location 3 and facility 5 cannot be assigned to location 9. What changes in your pyomo model or in lab5 ex2.txt file will you make? Make these changes, and solve the integer problem and report the solution.

More products