Il metodo del simplesso
I
implementazione matriciale
I
implementazione ”tableau”
rif. Fi 3.2;
Test di ottimalit` a
Test Opt Input: B
−1Output: ¯ c, opt ∈ {true, f alse}
Init. opt := f alse u
T= c
TBB
−1¯
c
F:= c
F− u
TF
Test if ¯ c
F= 0 then opt := true
Test di illimitatezza
Test Illim
Input: B
−1, indice h fuori base
Output: A ¯
h= B
−1A
h, illim ∈ {true, f alse}
Init. illim := f alse calcola ¯ A
h= B
−1A
hTest if ¯ a
ih≤ 0, i ∈ {1, . . . , m} then illim := true
Metodo del Simplesso (forma matriciale)
Input: A, b, c, B = [A
B(1), . . . , A
B(m)] Output: x sol. ottima OR illim = true Init. illim := f alse, opt := f alse
Main Loop while (illim = f alse and opt = f alse) calcola B
−1Test Opt(B
−1) → ¯ c, opt if (opt = true) then return h
xB
xF
i
= h
B−1b 0i
var. in else scegli h 6∈ {B(1), . . . , B(m)} con ¯ c
h< 0 Test Illim(B
−1, h) → ¯ A
h, illim
if (illim = true) then ”STOP: prob. illimitato”
else
var. out calcola t := arg min
i∈{1,...,m}{¯b
i/¯ a
ih: ¯ a
ih> 0}
Update B B(t) := h
End Loop end while
Esempio
min −3x
1+ 2x
2+ 4x
3s.t.
−x
1− x
2+ 2x
3+ x
4= 1 x
1− 2x
2+ x
3+ x
5= −1 x
1, x
2, x
3, x
4, x
5≥ 0
Base iniziale:
B(1) = 2, B(2) = 3 B = [A
2, A
3] =
−1 2
−2 1
Iter 1.
B
−1=
1/3 −2/3 2/3 −1/3
Esempio
Test Opt u
T= [2 4]
1/3 −2/3 2/3 −1/3
= [10/3 − 8/3]
¯
c
1= −3 − [10/3 − 8/3] h
−11
i
= 3
¯
c
4= 0 − [10/3 − 8/3] h
10
i
= −10/3
¯
c
5= 0 − [10/3 − 8/3] h
01
i
= 8/3 opt = f alse =⇒ sceglie var. entrante x
4Test Illim b = ¯
1/3 −2/3 2/3 −1/3
h
1−1
i = h
11
i , ¯ A
4=
1/3 −2/3 2/3 −1/3
h
10
i = h
1/32/3
i illim = f alse =⇒ sceglie var. uscente x
t(
¯b1¯ a14
= 3
¯b2
¯
a24
= 3/2 = θ =⇒ t = 2, x
B(2)= x
3var. uscente
Esempio
nuova base B = [A
2, A
4]
−1 1
−2 0
Iter 2.
B
−1=
0 −1/2 1 −1/2
Test Opt u
T= [2 0] =
0 −1/2 1 −1/2
= [0 − 1]
¯
c
1= −3 − [0 − 1] h
−11
i
= −2
¯
c
3= 4 − [0 − 1] h
21
i
= 5
¯
c
5= 0 − [0 − 1] h
01
i
= 1
opt = f alse =⇒ sceglie var. entrante x
1Esempio
Test Illim b = ¯
0 −1/2 1 −1/2
h
1−1
i
= h
1/23/2
i ,
A ¯
1=
0 −1/2 1 −1/2
h
−11
i
= h
−1/2−3/2
i
illim = true =⇒ STOP: problema illimitato
Questioni da definire
I
correttezza e convergenza del Metodo del Simplesso
I
individuazione della base iniziale
I
implementazioni efficienti
Il tableau del Simplesso
rappresentiamo il problema risp. ad una base:
c
TBc
TF0
B F b
premoltiplichiamo per B
−1c
TBc
TF0
I B
−1F B
−1b
Il tableau del Simplesso
sottraiamo alla riga 0 la matrice premoltiplicata per c
TBc
TB− c
TBc
TF− c
TBB
−1F −c
TBB
−1b
I B
−1F B
−1b
cio` e
0
Tc
TF− c
TBB
−1F −c
TBB
−1b
I B
−1F B
−1b
rappresentazione in forma canonica rispetto alla base B
Implementazione Tableau
Input: A, b, c, B = [A
B(1), . . . , A
B(m)] Output: x sol. ottima OR illim = true Init. illim := f alse, opt := f alse
costruisce il tableau iniziale in forma canonica Main Loop while (illimitato := f alse and opt := f alse) Row 0 if (¯ c
j≥ 0, j ∈ F ) then return h
xB
xF
i = h
B−1b 0i
var. in else scegli h 6∈ {B(1), . . . , B(m)} con ¯ c
h< 0
Col h if (¯ a
ih≤ 0, i = 1, . . . , m) then ”STOP: prob. illimitato”
else
var. out calcola t := arg min
i∈{1,...,m}{¯b
i/¯ a
ih: ¯ a
ih> 0}
Update B P IV OT (t, h)
B(t) := h
End Loop end while
Esempio
min −2x
1− 5x
2− x
3s.t.
x
1+ 3x
2+ x
4= 4 5x
2+ x
3+ x
5= 5 2x
1+ 4x
2+ x
3+ x
6= 6 x
1, x
2, x
3, x
4, x
5, x
6≥ 0
- 2 - 5 - 1 0 0 0 0
1 3 0 1 0 0 4 x
40 5 1 0 1 0 5 x
52 4 1 0 0 1 6 x
6tableau gi` a in forma canonica
Esempio
iter 1
- 2 - 5 - 1 0 0 0 0
1 3 0 1 0 0 4 x
40 5 1 0 1 0 5 x
52 4 1 0 0 1 6 x
6var entrante x
2t = arg min{4/3, 1, 6/4} = 2
=⇒ var uscente x
5P IV OT (t = 2, h = 2): ricavare x
2dalla riga t ”di pivot” e sostituirla nelle altre:
I
normalizzare la riga di pivot t = 2
I
sommare alla riga 1 la riga di pivot moltiplicata per −3
I
sommare alla riga 3 la riga di pivot moltiplicata per −4
I