0% found this document useful (0 votes)
41 views4 pages

ODM2022 Tutorial-2

This document provides exercises for modeling and solving linear programs. It includes examples of data fitting, moment problems, linear fractional programming, and project scheduling that can be formulated as linear programs. The exercises are to be solved using MATLAB and the YALMIP toolbox to model and solve the linear programs.

Uploaded by

ME
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

ODM2022 Tutorial-2

This document provides exercises for modeling and solving linear programs. It includes examples of data fitting, moment problems, linear fractional programming, and project scheduling that can be formulated as linear programs. The exercises are to be solved using MATLAB and the YALMIP toolbox to model and solve the linear programs.

Uploaded by

ME
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1

Optimal Decision Making MGT-483


Tutorial 2 — Exercises
RAO

In this tutorial you will practice (i) how to model some seemingly nonlinear optimiza-
tion problems as linear programs and (ii) and how to formulate and solve linear programs
in MATLAB. A linear programming formulation is attractive because (i) linear programs
are generally easier to solve than general convex or nonlinear programs and (ii) many
programming languages have built-in functions to formulate and numerically solve linear
programs.

Exercise 1 (Data fitting). We are given m data points of the form (xi , yi ), i = 1, . . . , m,
where xi is the input vector (e.g. the age and height of a person) and yi is the output (e.g.
the person’s weight). We wish to build a model that predicts the value of the variable y
from knowledge of the input vector x. The simplest approach is using a linear model of
the form y = θ ⊤ x, where θ is a parameter vector to be determined.
Given a particular parameter vector θ, the residual, or prediction error, at the ith data
point is defined as ei = yi − θ ⊤ xi . Given a choice between alternative models, one should
choose a model that explains the available data as best as possible, i.e., a model that
results in a small prediction error.

1. In order to minimize the worst-case prediction error, we solve

min max |yi − θ ⊤ xi |.


θ i

2. In order to minimize the sum of absolute prediction errors, we solve


m
X
min |yi − θ ⊤ xi |.
θ
i=1

Formulate these problems as linear programs.

Exercise 2 (Moment problem). Suppose that Z is a discrete random variable taking values
in the set {0, 1, . . . , K}, withPprobabilities p0 , p1 , . . . , pK , respectively. We are P
given the
K 2 K 2
mean value m1 = E[Z] = i=0 ipi and the second moment m2 = E[Z ] = i=0 i pi
of Z, and we would P like 4to obtain upper and lower bounds on the value of the fourth
moment E[Z 4 ] = K i=0 i pi of Z over all distributions with the given first- and second-
order moments.
Formulate two linear programming problems with decision variables p0 , p1 , . . . , pK that
allow you to compute these bounds.
2

Exercise 3 (Linear fractional programming). Consider the non-linear optimization problem


c⊤ x + d
min
x f ⊤x + g

s.t. Ax ≤ b
f ⊤ x + g ≥ ϵ,
where ϵ > 0.
Formulate a linear program that allows you to determine whether the optimal cost is less
than or equal to a given constant t.

Computational Exercises
Solve the following computational questions with MATLAB or Python (see the dedicated
noto tutorial for Python). Use the interface YALMIP and the solver LINPROG, which is
included in the optimization toolbox of MATLAB (if not you can try to manually install
it). YALMIP is available on moodle as the file ‘YALMIP.zip’ but better is to go directly
to https://yalmip.github.io/tutorial/installation/. and run (from your
MATLAB Command Window):

cd YALMIPfolderShouldbeHere
urlwrite(’https://github.com/yalmip/yalmip/archive/master.zip’,’yalmip.zip’);
unzip(’yalmip.zip’,’yalmip’)
addpath(genpath([pwd filesep ’yalmip’]));
savepath

For additional information on YALMIP please refer to http://users.isy.liu.se/


johanl/yalmip/pmwiki.php?n=Tutorials.Tutorials.
Guidelines for using LINPROG within YALMIP can be found at http://users.isy.
liu.se/johanl/yalmip/pmwiki.php?n=Solvers.LINPROG.
Exercise 4 (Solving LPs with MATLAB). Implement the following linear program step by
step.

min −5x1 − 4x2 − 6x3


x1 ,x2 ,x3
s.t. x1 ≥ 0, x2 ≥ 0, x3 ≥ 0
x1 − x2 + x3 ≤ 20
3x1 + 2x2 + 4x3 ≤ 42
3x1 + 2x2 ≤ 30
1. Add Yalmip to your Matlab path.
2. Declare the (column) vector of decision variables x1 , x2 and x3 .
x = sdpvar(3,1);
3. Implement the objective function.
objective = [-5; -4; -6]’*x; (or objective = -5*x(1) - 4*x(2) -
6*x(3);)
3

4. Implement the constraints.


constraints = [x >= 0];
constraints = [constraints, [1 -1 1; 3 2 4; 3 2 0]*x <= [20; 42;
30]];
5. Call LINPROG to solve the problem.
ops = sdpsettings(’solver’,’linprog’,’verbose’,0);
diagnosis = optimize(constraints, objective, ops);
6. Retrieve and display the solution.
x = value(x);
disp(x);

Exercise 5 (Project scheduling). In project scheduling we are given a project graph as


displayed in Figure 1. Each node i ∈ V = {1, . . . , n} in the graph represents a task, and
each arc (i, j) ∈ E ⊂ V × V represents a precedence relation: an arc from i to j means
that task j can only be initiated once task i is completed. The task durations are denoted
by {di }ni=1 . The objective is to minimize the completion time of the project (i.e., the
completion time of task n). This problem can be reformulated as a linear program of the
form

min sn + dn
s.t. si ≥ 0 ∀i ∈ {1, 2, . . . , n}
sv ≥ su + du ∀(u, v) ∈ E,
where the decision variable si represents the start time of task i, while s = (s1 , . . . , sn ) is
referred to as the project schedule. When implementing project scheduling problems, it
is convenient (but not necessary) to represent the project graph by an adjacency matrix
A ∈ {0, 1}n×n and the task durations by a vector d = {d1 , . . . , dn }⊤ ∈ Rn . In the example
of Figure 1, we set
   
0 1 0 1 0 0 4
 0 0 1 0 1 0   5 
   
 0 0 0 0 0 1   6 
A=   and d =  , (1)
 0 0 0 0 1 0 
  1 
 
 0 0 0 0 0 1   8 
0 0 0 0 0 0 5
where Aij = 1 if (i, j) ∈ E and Aij = 0 if (i, j) ∈
/ E.

1. Implement and solve a linear program that finds the optimal schedule for the project
given by A and d in (1).
2. What happens if we add the precedence (2, 1) to E, i.e., what happens if there is a
loop in the precedence graph?
3. Consider now a larger project. The data of this problem (A and d) is provided in
the file ‘Data.zip’. Implement and solve the linear program that finds the optimal
schedule for this project.
4

Figure 1: Project graph

You might also like