ODM2022 Tutorial-2
ODM2022 Tutorial-2
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.
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
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
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