• Non ci sono risultati.

Test di ottimalit` a

N/A
N/A
Protected

Academic year: 2021

Condividi "Test di ottimalit` a"

Copied!
15
0
0

Testo completo

(1)

Il metodo del simplesso

I

implementazione matriciale

I

implementazione ”tableau”

rif. Fi 3.2;

(2)

Test di ottimalit` a

Test Opt Input: B

−1

Output: ¯ c, opt ∈ {true, f alse}

Init. opt := f alse u

T

= c

TB

B

−1

¯

c

F

:= c

F

− u

T

F

Test if ¯ c

F

= 0 then opt := true

(3)

Test di illimitatezza

Test Illim

Input: B

−1

, indice h fuori base

Output: A ¯

h

= B

−1

A

h

, illim ∈ {true, f alse}

Init. illim := f alse calcola ¯ A

h

= B

−1

A

h

Test if ¯ a

ih

≤ 0, i ∈ {1, . . . , m} then illim := true

(4)

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

−1

Test Opt(B

−1

) → ¯ c, opt if (opt = true) then return h

x

B

xF

i

= h

B−1b 0

i

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

(5)

Esempio

min −3x

1

+ 2x

2

+ 4x

3

s.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



(6)

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

−1

1

i

= 3

¯

c

4

= 0 − [10/3 − 8/3] h

1

0

i

= −10/3

¯

c

5

= 0 − [10/3 − 8/3] h

0

1

i

= 8/3 opt = f alse =⇒ sceglie var. entrante x

4

Test Illim b = ¯

 1/3 −2/3 2/3 −1/3

 h

1

−1

i = h

1

1

i , ¯ A

4

=

 1/3 −2/3 2/3 −1/3

 h

1

0

i = h

1/3

2/3

i illim = f alse =⇒ sceglie var. uscente x

t

(

¯b1

¯ a14

= 3

¯b2

¯

a24

= 3/2 = θ =⇒ t = 2, x

B(2)

= x

3

var. uscente

(7)

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

−1

1

i

= −2

¯

c

3

= 4 − [0 − 1] h

2

1

i

= 5

¯

c

5

= 0 − [0 − 1] h

0

1

i

= 1

opt = f alse =⇒ sceglie var. entrante x

1

(8)

Esempio

Test Illim b = ¯

 0 −1/2 1 −1/2

 h

1

−1

i

= h

1/2

3/2

i ,

A ¯

1

=

 0 −1/2 1 −1/2

 h

−1

1

i

= h

−1/2

−3/2

i

illim = true =⇒ STOP: problema illimitato

(9)

Questioni da definire

I

correttezza e convergenza del Metodo del Simplesso

I

individuazione della base iniziale

I

implementazioni efficienti

(10)

Il tableau del Simplesso

rappresentiamo il problema risp. ad una base:

c

TB

c

TF

0

B F b

premoltiplichiamo per B

−1

c

TB

c

TF

0

I B

−1

F B

−1

b

(11)

Il tableau del Simplesso

sottraiamo alla riga 0 la matrice premoltiplicata per c

TB

c

TB

− c

TB

c

TF

− c

TB

B

−1

F −c

TB

B

−1

b

I B

−1

F B

−1

b

cio` e

0

T

c

TF

− c

TB

B

−1

F −c

TB

B

−1

b

I B

−1

F B

−1

b

rappresentazione in forma canonica rispetto alla base B

(12)

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

x

B

xF

i = h

B−1b 0

i

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

(13)

Esempio

min −2x

1

− 5x

2

− x

3

s.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

4

0 5 1 0 1 0 5 x

5

2 4 1 0 0 1 6 x

6

tableau gi` a in forma canonica

(14)

Esempio

iter 1

- 2 - 5 - 1 0 0 0 0

1 3 0 1 0 0 4 x

4

0 5 1 0 1 0 5 x

5

2 4 1 0 0 1 6 x

6

var entrante x

2

t = arg min{4/3, 1, 6/4} = 2

=⇒ var uscente x

5

P IV OT (t = 2, h = 2): ricavare x

2

dalla 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

sommare alla riga 0 la riga di pivot moltiplicata per 5

(15)

Esempio

iter 2

- 2 0 0 0 1 0 5

1 0 -3/5 1 -3/5 0 1 x

4

0 1 1/5 0 1/5 0 1 x

2

2 0 1/5 0 -4/5 1 2 x

6

var entrante x

1

t = arg min{1, 2/2} = 3

=⇒ var uscente x

6

P IV OT (t = 3, h = 1): ricavare x

1

dalla riga 3 ”di pivot” e sostituirla nelle altre

iter 3

0 0 1/5 0 1/5 1 7

0 0 -7/10 1 -1/5 -1/2 0 x

4

0 1 1/5 0 1/5 0 1 x

2

1 0 1/10 0 -2/5 1/2 1 x

1

¯

c ≥ 0 =⇒ x

T

=

 1 1 0 0 0 0 

soluzione ottima di valore −7

Riferimenti

Documenti correlati

- The panel object that holds the components can be the event listener for those components - Event generators send messages (call methods) to registered

“decadent.” The Platonists see it has having no ruling principle, no cen- ter, no structure. The positivists see it as having no respect for hard fact, for that area

[r]

Read the sentences about the animals below and write “TRUE”

Member(E, lista): verifica se l’elemento E è presente nella lista Append(E, lista): inserisce l’elemento dato E in coda alla lista (due. versioni: nella prima versione uso di

Leggi x e S=s1 s2...sn. Assegna true ad

● ad ogni runlevel è idealmente associato un insieme di servizi attivi quando init si trova in quel runlevel. ● a runtime è possibile indicare ad init di cambiare

● anacron viene solitamente eseguito al boot della macchina e periodicamente via cron. ● per ognuno dei job