[SOLVED] IE507 Lab 2

30.00 $

Category: Tags: ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon lab2-jomnzh.zip (127.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Instructions:

In this session, we will continue to use Pyomo modeling language and software. We will see more useful constructs which will help in modelling problems which have many variables and constraints. Please follow the instructions given below:

  • Please use different notebooks for solving different problems.
  • The name of your notebook for Exercise 1 should be YOURROLLNUMBER IE507 Lab2 Ex1.ipynb. Similarly, The name of your notebook for Exercise 2 should be YOURROLLNUMBER IE507 Lab2 Ex2.ipynb, etc.
  • 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.
    For details on numpy python package, please consult https://numpy.org/doc/stable/numpy-ref. pdf. This file has been uploaded in moodle as well.

    There are only 3 exercises. 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.

    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 Lab2 and copy your .ipynb files to the folder. Then zip the folder to create YOURROLLNUMBER IE507 Lab2.zip. Then upload only the .zip file to Moodle. These instructions are also provided in the video.

    The deadline for today’s lab submission is tomorrow, 11.59 PM IST.

1

IE507, Modeling and Computation Lab
Lab 02 26-August-2020

Exercise 1: [6 Marks]
In the practice problem, we saw that python numpy arrays can be used to store the coefficients of the objective function and constraints. In this exercise, we will consider a slight variation and consider the problem given below.

min c1x1 +c2x2 +…+cNxN, x1+x2+…+xN ≤b1, w1x1+…+wNxN =b2, xi ≤ ui,

xi ≥ li,

i = 1,…,N, i = 1,…,N.

1. Now suppose we want to solve the problem with 10 variables. Modify the code in practice problem so that you can solve the problem given above with 10 variables. You may assume that

b1 = 151.2,
b2 = 44.6,
c = [−10.1, 20.15, 60.5, 80.05, 0.15, 40.5, −0.05, −30.02, 40.65, 0.125]; w = [0, 1.6, −2.02, 0, 1.01, −2.005, 0, 1.39, 1, −1.214];
l = [−∞,1,0,0,7,0,−∞,−∞,1,1],
u = [4,3,+∞,2,10,+∞,13,20,+∞,21]

2. [R] Solve the new problem and report the optimal solution and the value of the objective function (or cost).

2

IE507, Modeling and Computation Lab
Lab 02 26-August-2020

Exercise 2: [8 Marks] We will now consider another general formulation of the form given below:

min c⊤x,
s.t Ax≤b

l ≤ x ≤ u.

wherec,x,landuareN×1vectorsandc⊤x=􏰁Ni=1cixi. AisaM×N matrixandbisM×1 vector. Ax ≤ b results in M constraints and note that i-th row of Ax ≤ b can be written as a constraint of the form:

ai1x1 +ai2x2 +…+aiNxN ≤bi. We will solve the general form using concrete values given below:

c = [8.6, −20.35, 61.5, 39.05, −0.15, 40.5, −0.05, −30.02, 40.65, 5.125];

0 1−20 1−2011−1 A=−1 1 −3 2.5 0 1.4 0 −2 1 −1.5 −0.45 4.78 −2 −3.22 −1.3 1 −1 0 0 0.25 

1100110110 b = [55.4, 67.9, 21.43, 12.7]

l = [−∞,−∞,0,0,−57,0,−∞,−3,4,1], u = [4,∞,+∞,2,10,45,13,20,+∞,+∞]

We will now see some instructions to prepare your code to solve this general formulation.

Preparing the code for solving the general formulation:

  • Recall that we created a variable N to denote the number of variables. Similarly create a variable M to denote the number of constraints. Use appropriate value for M based on the concrete problem given above.
  • Recall that we used two arrays named constr1 coef p and constr2 coef q for storing the coefficients of the two constraints. Now, instead we will create a single two-dimensional numpy array with name constr coef A to store the coefficients of all constraints. Check the numpy documentation and see how to create a two-dimensional numpy array. Create the array with the values given in the matrix A given above.
  • Similarly we used two variables constr1 rhs b1 and constr1 rhs b2 for storing the values used in RHS of first and second constraints respectively. Now, instead we will create a single numpy array constr rhs b and store the values in b array given above.
  • Also recall that we used a ConstraintList() for adding the constraints. We added each constraint separately. Instead of adding each constraint separately, we will try to add the constraints in a loop. For this purpose, let us create a list using the following command

    row_indices = np.arange(M)
    Check the contents of this list using a print statement. Now create a for loop to load the

    constraint to the list ConstraintList(). Your code should be of the form as given below:

          for <fill in appropriate syntax>:
              model.constraints.add(<fill in appropriate syntax>)
    

3

IE507, Modeling and Computation Lab
Lab 02 26-August-2020

  • Modify the upper bound and lower bound arrays in your code appropriately with the values given above in l and u arrays.
  • Print the model to check if the constraints have been added properly.
  • You are now ready to answer the questions. Question:
  • [R] Solve the problem and report the optimal solution and the value of the objective function (or cost).
  • [R] Which constraints are active and which constraints are inactive? Explain with proper reasons.

4

IE507, Modeling and Computation Lab
Lab 02 26-August-2020

Exercise 3: Alloy Mix Problem. [15 Marks]
Kekra Metal Co. produces 250 tons of metallic alloy product of composition: 45% Chromium, 35% Zinc, and 20% Silver. In order to produce this alloy, it can mix 10 available alloys: A-1, A-2, . . . , A-10. The alloys have the following composition and costs.

% of Chromium
% of Zinc
% of Silver
in-house stock (Tons) in-house cost (per Ton) purchase cost (per Ton)

A-8 A-9 A-10 30 30 30 55 40 15 0 9 35 40 60 84

A-1 80 15 5 10 35 72

A-2 A-3 75 75 15 10 10 15

7 8 50 58 95 110

A-4 A-5 A-6 A-7
60 55 55 40 35 20 25 10 50 15 20 20 35 10 50 15 8 15 12 10 60 44 39 45 55

125 88 74 95 115

The company can either use the
them from market. The stocks available in the company are limited while the quantity available in market is unlimited. You are given the task of finding how much of each raw-material should be put in the final mix to obtain 250 Tons of the product.

  1. [R] Formulate an LP model that can be solved to find the optimal mix of raw-material alloys.
  2. Modify the code used in Exercise 2 with appropriate number of variables, number of con- straints, coefficient arrays, lower bound and upper bound arrays to construct a model for this problem.
  3. [R] Solve the model and report the optimal value and the optimal solution.
  4. [R] Among the alloys that need to be bought from the market, which three alloys are ranked

    high in terms of the quantities to be bought and which three alloys are ranked low?

  5. [R] Is there any alloy whose stock is completely utilized? Why?
  6. [R] Is there any alloy which need not be acquired from market? Why?

stocks of raw material alloys available in the company or purchase

5

  • lab2-jomnzh.zip