Docsity

Linear Optimization Homework Solution for CUHK-Shenzhen - School of Data Science, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
The Chinese University of Hong Kong, Shenzhen
School of Data Science
MAT3007 ·Homework 1
Due: 11:59pm, September 22 (Friday), 2023
Instructions:
•Homework problems must be carefully and clearly answered to receive full credit. Complete
sentences that establish a clear logical progression are highly recommended.
•Please submit your assignment on Blackboard.
•The homework must be written in English.
•Late submission will not be graded.
•Each student must not copy homework solutions from another student or from any other
source.
•For those questions that ask you to write MATLAB/Python codes to solve the problem.
Please attach the code to the homework. You also need to clearly state (write or type) the
optimal solution and the optimal value you obtained. However, you do not need to attach
the outputs in the command window of MATLAB/Python.
Problem 1 (25pts). Modeling
A company produces two kinds of products. A product of the first type requires 1/8 hours of
assembly labor, 1/2 hours of testing, and $1.2 worth of raw materials. A product of the second
type requires 1/4 hours of assembly, 1/6 hours of testing, and $0.9 worth of raw materials. Given
the current personnel of the company, there can be at most 90 hours of assembly labor and 80
hours of testing each day. Products of the first and second type have a market value of $9 and $8
respectively.
(a) Formulate a linear optimization that maximizes the daily profit of the company.
(b) Write the standard form of the LP you formulated in part (a).
(c) Consider the following modification to the original problem: Suppose that up to 40 hours of
overtime assembly labor can be scheduled, at a cost of $8 per hour. Can it be easily incorporated
into the linear optimization formulation and how?
(d) Solve the LP using software (for the optimization problem formulated in part (a)).
Solution.
(a) Let x1be the number of type 1 product, and x2be the number of type 2 product.
maximize (9 −1.2)x1+ (8 −0.9)x2
s.t. 1
8x1+1
2x2≤90
1
4x1+1
6x2≤80
x1, x2≥0
1
pf3
pf4
pf5

Partial preview of the text

Download Linear Optimization Homework Solution for CUHK-Shenzhen - School of Data Science and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

The Chinese University of Hong Kong, Shenzhen School of Data Science

MAT3007 · Homework 1 Due: 11:59pm, September 22 (Friday), 2023 Instructions:

  • Homework problems must be carefully and clearly answered to receive full credit. Complete sentences that establish a clear logical progression are highly recommended.
  • Please submit your assignment on Blackboard.
  • The homework must be written in English.
  • Late submission will not be graded.
  • Each student must not copy homework solutions from another student or from any other source.
  • For those questions that ask you to write MATLAB/Python codes to solve the problem. Please attach the code to the homework. You also need to clearly state (write or type) the optimal solution and the optimal value you obtained. However, you do not need to attach the outputs in the command window of MATLAB/Python.

Problem 1 (25pts). Modeling A company produces two kinds of products. A product of the first type requires 1/8 hours of assembly labor, 1/2 hours of testing, and $ 1 .2 worth of raw materials. A product of the second type requires 1/4 hours of assembly, 1/6 hours of testing, and $ 0 .9 worth of raw materials. Given the current personnel of the company, there can be at most 90 hours of assembly labor and 80 hours of testing each day. Products of the first and second type have a market value of $9 and $ 8 respectively. (a) Formulate a linear optimization that maximizes the daily profit of the company.

(b) Write the standard form of the LP you formulated in part (a).

(c) Consider the following modification to the original problem: Suppose that up to 40 hours of overtime assembly labor can be scheduled, at a cost of $8 per hour. Can it be easily incorporated into the linear optimization formulation and how?

(d) Solve the LP using software (for the optimization problem formulated in part (a)).

Solution.

(a) Let x 1 be the number of type 1 product, and x 2 be the number of type 2 product.

maximize (9 − 1 .2)x 1 + (8 − 0 .9)x 2 s.t. 18 x 1 + 12 x 2 ≤ 90 1 4 x^1 +^

1 6 x^2 ≤^80 x 1 , x 2 ≥ 0

(b) The standard form is as follows.

minimize −(9 − 1 .2)x 1 − (8 − 0 .9)x 2 s.t. 18 x 1 + 12 x 2 + s 1 = 90 1 4 x^1 +^

1 6 x^2 +^ s^2 = 80 x 1 , x 2 , s 1 , s 2 ≥ 0

(c) Let x 3 be the number of overtime hours. We can form the following LP.

maximize (9 − 1 .2)x 1 + (8 − 0 .9)x 2 − 8 x 3 s.t. 18 x 1 + 12 x 2 ≤ 90 + x 3 1 4 x^1 +^

1 6 x^2 ≤^80 x 3 ≤ 40 x 1 , x 2 , x 3 ≥ 0

(d) The optimal objective value is about 2724. The optimal solutions are x 1 = 240, x 2 = 120.

cvx begin variables x1 x minimize -(9-1.2)x1 - (8-0.9)x subject to 1/8x1 + 1/2x2 <= 90; 1/4x1 + 1/6x2 <= 80; x1 >= 0; x2 >= 0; cvx end

Problem 2 (25pts). Reformulate NLP as LP Reformulate the following problems as linear programming:

minimize 2 x 2 + |x 1 − x 3 | subject to |x 1 + 2| + |x 2 | ≤ 5 x^23 ≤ 1

Please also write down its standard form.

Solution.

Let y 1 = |x 1 − x 3 | , y 2 = |x 1 + 2| , y 3 = |x 2 |.

From/To 1 2 3 4 5 1 − 20 13 11 28 2 20 − 18 8 46 3 13 18 − 9 27 4 11 8 9 − 20 5 28 46 27 20 −

Table 1: Cost of moving a car

1 2 3 4 5 Present 110 335 400 420 610 Need 150 200 600 200 390

Table 2: Number of current and needed cars

Let xij denote the number of cars moving from place i to j.

minimize

i=

j=1 cij^ xij s.t.

i 6 =1 xi^1 −^

∑^ j^6 =1^ x^1 j^ ≥^150 −^110 i 6 =2 xi^2 −^

∑^ j^6 =2^ x^2 j^ ≥^200 −^335 i 6 =3 xi^3 −^

∑^ j^6 =3^ x^3 j^ ≥^600 −^400 i 6 =4 xi^4 −^

∑^ j^6 =4^ x^4 j^ ≥^200 −^420 i 6 =5 xi^5 −^

j 6 =5 x^5 j^ ≥^390 −^610 xij ≥ 0 ∀i, j xij ∈ Z ∀i, j.

c = [0 20 13 11 28; 20 0 18 8 46; 13 18 0 9 27; 11 8 9 0 20; 28 46 27 20 0];

cvx begin variables x(5,5)

minimize sum(sum(c.*x)) subject to

x(2,1)+x(3,1)+x(4,1)+x(5,1)-x(1,2)-x(1,3)-x(1,4)-x(1,5)>=150-110; x(1,2)+x(3,2)+x(4,2)+x(5,2)-x(2,1)-x(2,3)-x(2,4)-x(2,5)>=200-335; x(1,3)+x(2,3)+x(4,3)+x(5,3)-x(3,1)-x(3,2)-x(3,4)-x(3,5)>=600-400; x(1,4)+x(2,4)+x(3,4)+x(5,4)-x(4,1)-x(4,2)-x(4,3)-x(4,5)>=200-420; x(1,5)+x(2,5)+x(3,5)+x(4,5)-x(5,1)-x(5,2)-x(5,3)-x(5,4)>=390-610; x >= zeros(5,5); cvx end

The optimal solutions are x 41 = 40, x 43 = 200, x 24 = 20, with the rest xij = 0. Since the solution satisfy the integer constraint, then it must be optimal to the original problem since we enlarge the feasible region by relaxing the integer constraint. The optimal objective value is 3195.

Problem 4 (25pts). Write a software code to use linear optimization to solve the shortest path problem. Suppose the input of the problem will be an n × n matrix of W , where wij is the length of the path from i to j. In our implementation, we always use 1 to denote the source node (the S node in the lecture slides), and n to denote the terminal node (the T node in the lecture slides). In addition, we assume for any i and j, there is a path, i.e., the set of E is all pairs of nodes. This is without loss of generality since one can set wij and wji to be an extremely large number if there is no edge between i and j, effectively eliminating it from consideration.

S T

Figure 1: The graph of the shortest path problem

You are asked to solve the optimization problem formulated in the lecture slides using software, with the given labeling shown in Figure 1. Basically, you need to input the W matrix for this case, and then solve it. To solve this problem, you can relax the binary integer constraint xij ∈ { 0 , 1 } to 0 ≤ xij ≤ 1. What is the optimal solution, i.e., the optimal path, for the relaxed problem? Is it optimal to the original problem? If yes, justify it.

Solution. The optimal solutions are x(1, 3) = x(3, 5) = x(5, 7) = x(7, 8) = 1, with the rest x(i, j) = 0. The optimal objective value is 8. Since the solutions are either 0 or 1, satisfying the binary integer constraints, it must be optimal to the original binary integer program since we have enlarged the feasible region.

M = 100; W = [M, 5, 4, M, M, M, M, M; 5, M, M, 3, M, 7, M, M; 4, M, M, M, 1, 2, M, M; M, 3, M, M, 2, M, M, M; M, M, 1, 2, M, M, 2, 5; M, 7, 2, M, M, M, M, 3; M, M, M, M, 2, M, M, 1;