• Nenhum resultado encontrado

Métodos Numéricos. MEI - Logística e distribuição Linguagem de modelação AMPL 2004/2005. A. Ismael F. Vaz - Departamento de Produção e Sistemas

N/A
N/A
Protected

Academic year: 2021

Share "Métodos Numéricos. MEI - Logística e distribuição Linguagem de modelação AMPL 2004/2005. A. Ismael F. Vaz - Departamento de Produção e Sistemas"

Copied!
34
0
0

Texto

(1)

MEI - Logística e distribuição Linguagem de modelação AMPL

2004/2005

(2)

AMPL

AMPL significa A Mathematical Programming Language.

O AMPL é um software comercial, mas existe uma versão Student Edition que é limitada (300 variáveis, 300 restrições).

Página Web: http://www.ampl.com

O AMPL é constituído por um único executável (ampl(.exe), dependendo

do sistema operativo).

(3)

Esquema de ligações

ficheiro .sol ficheiro .nl

Transparente para o utilizador

Solver (LOQO, MINOS, etc)

AMPL

(4)

Exemplo em AMPL - hs014.mod

var x {1..2};

minimize obj:

(x[1] - 2)^2 + (x[2]-1)^2

;

subject to constr1: x[1]^2/4 + x[2]^2 <= 1;

subject to constr2: x[1] - 2*x[2] = -1;

let x[1] := 2;

let x[2] := 2;

(5)

#printf "optimal solution as starting point \n";

#let x[1] := 0.822876;

#let x[2] := 0.911438;

option solver loqo;

option loqo_options ’verbose 2’;

solve;

display x;

display obj;

display obj - 9 + 2.875*sqrt(7);

(6)

Comentários

Problema com n = 2, m = 2 (uma restrição de desigualdade e uma de igualdade).

Aproximação inicial x = (2, 2)

T

.

Solução do problema como comentário.

O comando solve indica ao AMPL que se pretende resolver o problema.

O AMPL escreve um ficheiro temporário de extensão .nl e executa o

solver com os argumentos stub -AMPL. Se não se usar a opção solver o AMPL executa o solver por defeito (minos). O AMPL suspende a sua

execução até que o solver termine e produza um ficheiro de extensão .sol.

(7)

O AMPL em ambiente MSDOS

C:\AMPL>dir

O volume na unidade C não tem nome

O número de série do volume é 3098-4163 Directório de C:\AMPL

12-06-2004 10:37 <DIR> . 12-06-2004 10:37 <DIR> ..

02-11-2002 17:56 675.840 AMPL.EXE 12-01-2005 11:36 420 hs014.mod 15-10-2003 10:05 401.408 loqo.exe

13-05-2004 18:15 45 loqopasswd.txt

13-05-2004 18:15 7 loqosu.txt

5 ficheiro(s) 1.077.720 bytes

2 Dir(s) 117.566.636.032 bytes livres

(8)

C:\AMPL>ampl

ampl: var x{1..2};

ampl: let x[1]:=2;

ampl: let x[2]:=2;

ampl: display x;

x [*] :=

1 2 2 2

;

ampl: minimize obj: (x[1]-2)^2+(x[2]-1)^2;

ampl: display obj;

obj = 1

ampl: var x;

x is already defined

(9)

context: var >>> x; <<<

ampl: reset;

ampl: model hs014.mod;

LOQO 6.06: verbose 2

variables: non-neg 0, free 2, bdd 0, total 2

constraints: eq 1, ineq 1, ranged 0, total 2

nonzeros: A 4, Q 2

---

| Primal | Dual | Sig

Iter | Obj Value Infeas | Obj Value Infeas | Fig Status P M - - - -

1 1.000000e+000 5.6e-001 -9.000000e+000 1.1e+000

nonzeros: L 5, arith_ops 28

2 2.612376e-001 2.2e-001 -1.590061e+000 2.3e-001

3 6.252048e-001 8.9e-002 8.337782e-001 3.4e-002 1

4 9.790998e-001 3.9e-002 1.321358e+000 1.6e-003 1

5 1.271243e+000 1.5e-002 1.490126e+000 8.2e-003 1

(10)

6 1.360436e+000 3.0e-003 1.422519e+000 2.7e-003 2 7 1.390314e+000 2.8e-004 1.397006e+000 3.3e-004 3 8 1.393300e+000 1.5e-005 1.393659e+000 1.8e-005 4

9 1.393457e+000 7.3e-007 1.393475e+000 9.1e-007 5 PF DF 10 1.393465e+000 3.6e-008 1.393465e+000 4.6e-008 6 PF DF 11 1.393465e+000 1.8e-009 1.393465e+000 2.3e-009 8 PF DF ---

OPTIMAL SOLUTION FOUND

LOQO 6.06: optimal solution (11 iterations, 11 evaluations) primal objective 1.39346496

dual objective 1.393465005 x [*] :=

1 0.822876 2 0.911438

;

obj = 1.39346

(11)

obj - 9 + 2.875*sqrt(7) = -2.06983e-08 ampl: quit;

C:\AMPL>

no entanto o mais usado é editar o ficheiro .mod e executar directamente.

C:\AMPL>ampl hs014.mod LOQO 6.06: verbose 2 ...

obj - 9 + 2.875*sqrt(7) = -2.06983e-08

C:\AMPL>

(12)

O AMPL aceita um conjunto de opções na linha de comandos, por exemplo

C:\AMPL>ampl -v

AMPL Student Version 19991027 (MS VC++ 6.0) ampl: quit;

C:\AMPL>ampl -?

Usage: ampl [options] [file [file...]]

No file arguments means read from standard input, as does - by itself.

Options:

-Cn {0 = suppress Cautions; 1 = default; 2 = treat as error;}*

-L {fully eliminate linear definitional constraints and var = decls}*

-P {skip presolve -- same as "option presolve 0;" }

-S {substitute out definitional constraints (var = expression)}*

-T {show genmod times for each item}*

-enn {exit (if nn > 0) or abort command at |nn|-th error; 0 = no exit}*

-f {do not treat unavailable functions of constant args as variable}*

(13)

-ix {import functions from x; specify -i? for details } -ooutopt {specify -o? for details}*

-s[seed] {seed for random numbers; -s means current time}*

-t {show times}*

-v {show version; -v? shows other -v options}

-?? {show debug options}

* Equivalent option settings:

-Cn option Cautions n; -L option linelim 1;

-P option presolve 0; -S option substout 1;

-T option gentimes 1; -enn option eexit nn;

-f option funcwarn 1; -ofstub option outopt fstub;

-s option randseed ’’; -snn option randseed nn;

-t option times 1;

C:\AMPL>

Existe a possibilidade de separar os problemas em diversos ficheiros e

(14)

depois executar os ficheiros em sequência. O exemplo hs119.mod poderia usar 3 ficheiros com o modelo do problemas, dados e execução do solver.

hs119.mod

param a {1..16,1..16}, default 0;

param b {1..8, 1..16}, default 0;

param c {1..8}, default 0;

var x {1..16} >= 0, <= 5;

minimize obj:

sum {i in 1..16} sum {j in 1..16}

a[i,j]*(x[i]^2 + x[i] + 1)*(x[j]^2 + x[j] + 1)

;

subject to constr1 {i in 1..8}: sum {j in 1..16} b[i,j]*x[j] = c[i];

(15)

hs119 1.dat

data;

param a :=

1 1 1

1 4 1

1 7 1

1 8 1

1 16 1

2 2 1

2 3 1

2 7 1

2 10 1

3 3 1

3 7 1

3 9 1

3 10 1

(16)

3 14 1

4 4 1

4 7 1

4 11 1

4 15 1

5 5 1

5 6 1

5 10 1

5 12 1

5 16 1

6 6 1

6 8 1

6 15 1

7 7 1

7 11 1

7 13 1

8 8 1

(17)

8 10 1 8 15 1 9 9 1 9 12 1 9 16 1 10 10 1 10 14 1 11 11 1 11 13 1 11 12 1 12 14 1 13 13 1 13 14 1 14 14 1 15 15 1 16 16 1

;

(18)

param b :=

1 1 0.22 1 2 0.20 1 3 0.19 1 4 0.25 1 5 0.15 1 6 0.11 1 7 0.12 1 8 0.13

1 9 1

2 1 -1.46

2 3 -1.30

2 4 1.82

2 5 -1.15

2 7 0.80

2 10 1

(19)

3 1 1.29

3 2 -0.89

3 5 -1.16

3 6 -0.96

3 8 -0.49

3 11 1

4 1 -1.10

4 2 -1.06

4 3 0.95

4 4 -0.54

4 6 -1.78

4 7 -0.41

4 12 1

5 4 -1.43

5 5 1.51

5 6 0.59

5 7 -0.33

(20)

5 8 -0.43

5 13 1

6 2 -1.72

6 3 -0.33

6 5 1.62

6 6 1.24

6 7 0.21

6 8 -0.26

6 14 1

7 1 1.12

7 4 0.31

7 7 1.12

7 9 -0.36

7 15 1

8 2 0.45

8 3 0.26

8 4 -1.10

(21)

8 5 0.58 8 7 -1.03 8 8 0.10 8 16 1

;

param c :=

1 2.5 2 1.1 3 -3.1 4 -3.5 5 1.3 6 2.1 7 2.3 8 -1.5

;

(22)

let x[1] := 10;

let x[2] := 10;

let x[3] := 10;

let x[4] := 10;

let x[5] := 10;

let x[6] := 10;

let x[7] := 10;

let x[8] := 10;

let x[9] := 10;

let x[10] := 10;

let x[11] := 10;

let x[12] := 10;

let x[13] := 10;

let x[14] := 10;

let x[15] := 10;

let x[16] := 10;

(23)

display obj;

hs119 2.dat

data;

param a :=

1 1 1

1 4 1

1 7 1

1 8 1

1 16 1

2 2 1

2 3 1

2 7 1

2 10 1

3 3 1

3 7 1

(24)

3 9 1

3 10 1

3 14 1

4 4 1

4 7 1

4 11 1

4 15 1

5 5 1

5 6 1

5 10 1

5 12 1

5 16 1

6 6 1

6 8 1

6 15 1

7 7 1

7 11 1

(25)

7 13 1

8 8 1

8 10 1

8 15 1

9 9 1

9 12 1

9 16 1

10 10 1

10 14 1

11 11 1

11 13 1

11 12 1

12 14 1

13 13 1

13 14 1

14 14 1

15 15 1

(26)

16 16 1

;

param b :=

1 1 0.22 1 2 0.20 1 3 0.19 1 4 0.25 1 5 0.15 1 6 0.11 1 7 0.12 1 8 0.13

1 9 1

2 1 -1.46

2 3 -1.30

2 4 1.82

2 5 -1.15

(27)

2 7 0.80

2 10 1

3 1 1.29

3 2 -0.89

3 5 -1.16

3 6 -0.96

3 8 -0.49

3 11 1

4 1 -1.10

4 2 -1.06

4 3 0.95

4 4 -0.54

4 6 -1.78

4 7 -0.41

4 12 1

5 4 -1.43

5 5 1.51

(28)

5 6 0.59

5 7 -0.33

5 8 -0.43

5 13 1

6 2 -1.72

6 3 -0.33

6 5 1.62

6 6 1.24

6 7 0.21

6 8 -0.26

6 14 1

7 1 1.12

7 4 0.31

7 7 1.12

7 9 -0.36

7 15 1

8 2 0.45

(29)

8 3 0.26 8 4 -1.10 8 5 0.58 8 7 -1.03 8 8 0.10 8 16 1

;

param c :=

1 2.5

2 1.1

3 -3.1

4 -3.5

5 1.3

6 2.1

7 2.3

8 -1.5

(30)

;

printf "optimal solution as starting point \n";

let x[1] := 0.03984735;

let x[2] := 0.7919832;

let x[3] := 0.2028703;

let x[4] := 0.8443579;

let x[5] := 1.126991;

let x[6] := 0.9347387;

let x[7] := 1.681962;

let x[8] := 0.1553009;

let x[9] := 1.567870;

let x[10] := 0;

let x[11] := 0;

let x[12] := 0;

let x[13] := 0.6602041;

(31)

let x[14] := 0;

let x[15] := 0.6742559;

let x[16] := 0;

display obj;

hs119 1.run

option solver loqo;

option loqo_options ’verbose 2’;

solve;

display x;

display obj;

display obj - 244.899698;

hs119 2.run

(32)

option solver loqo;

option loqo_options ’verbose 10’;

solve;

display x;

display obj;

display obj - 244.899698;

C:\AMPL>ampl hs119.mod hs119_1.dat hs119_1.run obj = 566766

LOQO 6.06: verbose 2

variables: non-neg 0, free 0, bdd 16, total 16

constraints: eq 8, ineq 0, ranged 0, total 8

nonzeros: A 53, Q 78

(33)

...

OPTIMAL SOLUTION FOUND

LOQO 6.06: optimal solution (28 iterations, 28 evaluations) primal objective 244.8996998

dual objective 244.8996852 x [*] :=

1 0.0398475 2 0.791983 3 0.20287 4 0.844358 5 1.26991 6 0.934739 7 1.68196 8 0.155301 9 1.56787

10 9.11706e-09

(34)

11 6.40802e-09 12 1.27449e-07 13 0.660204 14 2.16056e-08 15 0.674256 16 3.12387e-09

;

obj = 244.9

obj - 244.899698 = 1.78153e-06

C:\AMPL>

Referências

Documentos relacionados

• “…Se puder verificar equipes incompletas no início da próxima aula seria uma mão

Rule of Least Surprise: In interface design, always do the least surprising thing.. Rule of Silence: When a program has nothing surprising to say, it should

• Simulating Server Push with Client Pull and

Tal processo não foi possível uma vez que a empresa apresenta muitos equipamentos e que a versão do (AMPL) utilizada possuía restrições a nível de memória

a sociedade, que poderiam ter morrido em lugar de meu filho. Por que Deus teria que buscar exatamente o meu menino com apenas dez anos? Senti vontade de esmur- rar algue m,

Parreira Sou ainda o mesmo que fui outrora ainda hoje os mesmos olhos olham por dentro das mesmas pupilas e procuram o mesmo infinito ha quarenta anos que sonho o mesmo sonho

Muitos dos problemas disponíveis para o AMPL e GAMS são oriundos da colecção de problemas do CUTE. O CUTEr é software de domínio público

• Simulating Server Push with Client Pull and