SlideShare une entreprise Scribd logo
1  sur  10
Télécharger pour lire hors ligne
GLPK

Formato LP

Formato MathProg

Notas

Introdução à Otimização

Utilizando o GLPK
Haroldo Gambini Santos
Universidade Federal de Ouro Preto

29 de março de 2011

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

1 / 30

Formato MathProg

Conteúdo

1

GLPK

2

Formato LP

3

Notas

Formato MathProg

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

2 / 30

Formato MathProg

GLPK

Notas

GNU Linear Programming Kit
resolvedor de problemas lineares, incluindo problemas de
programação inteira
código aberto, disponível gratuitamente
farta documentação

Introdução à Otimização,

Utilizando o GLPK

3 / 30
GLPK

Formato LP

Formato MathProg

GLPK

Notas

Instalação
Windows:
http://glpklabw.sourceforge.net/

Linux (debian/ubuntu e derivadas):
sudo apt-get install glpk

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

4 / 30

Formato MathProg

GLPK

Notas

Obtendo Ajuda
Pacote disponível em: http://www.gnu.org/software/glpk/
doc)
examples)

Manuais em PDF (diretório
Exemplos (diretório

Lista de Discussão: help-glpk@gnu.org

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

5 / 30

Formato MathProg

Introdução

Notas

Formatos conhecidos para entrada de programas lineares:
MPS Mathematical Programming System :
padrão da indústria
pouco intuitivo, confuso e com limitações

LP CPLEX LP le format :

padrão criado para uso com o resolvedor CPLEX
mais fácil e prático do que o formato MPS
aceito nos principais resolvedores modernos
arquivos podem ser convertidos para MPS

Introdução à Otimização,

Utilizando o GLPK

6 / 30
GLPK

Formato LP

Formato MathProg

Formato LP

Notas

Componentes
função objetivo
restrições
informações de variáveis
limites
variáveis inteiras genéricas
variáveis binárias

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

7 / 30

Formato MathProg

Problema da Dieta

Notas

Dieta.lp

§

Minimize

¤

obj : 3 x1 + 2 . 5 x2

Subject to

v i t a m i n a s : 6 x1 + 4 x2 = 32
p r o t e i n a s : 5 x1 + 6 x2 = 36

End

¦

¥

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

8 / 30

Formato MathProg

Resolvendo

Notas

Comando
glpsol --cpxlp dieta.lp -o sol.txt
Problem:
Rows:
Columns:
Non-zeros:
Status:
Objective:

sol.txt
2
2
4
OPTIMAL
obj = 17.75 (MINimum)

No. Row name St
Activity
Lower bound Upper bound
------ ------------ -- ------------- ------------- ------------1 vitaminas
NL
32
32
2 proteinas
NL
36
36
No.
-----1
2

Column name
-----------x1
x2

St Activity
Lower bound Upper bound
-- ------------- ------------- ------------B
3
0
B
3.5
0

Introdução à Otimização,

Utilizando o GLPK

9 / 30
GLPK

Formato LP

Formato MathProg

Limites e Integralidade

Notas

Podem ser especicadas restrições especícas sobre algumas
variáveis
Essas restrições são informadas após a seção das restrições
normais e podem ser dos seguintes tipos:
Restrição de limites - Seção Bounds:
Subject to
...
Bounds
0 = x1 = 40
2 = x4 = 3

Exemplo Limites

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

Limites e Integralidade

10 / 30

Formato MathProg

Notas

(cont.)

Para variáveis para as quais não são permitidos valores
fracionários temos as seções:
General: variáveis inteiras de modo geral
Binary: variáveis binárias que somente podem assumir
valor zero ou um
Exemplo Integralidade

Subject to
...
Binary
x3
General
x1
x2

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

11 / 30

Formato MathProg

Problema da Dieta

Notas

DietaInt.lp

§

Minimize

¤

obj : 3 x1 + 2 . 5 x2

Subject to

v i t a m i n a s : 6 x1 + 4 x2 = 32
p r o t e i n a s : 5 x1 + 6 x2 = 36

General
x1
x2

End

¦

¥
Introdução à Otimização,

Utilizando o GLPK

12 / 30
GLPK

Formato LP

Formato MathProg

Nova Solução

Notas

sol.txt

Problem:
Rows:
2
Columns:
2 (2 integer, 0 binary)
Non-zeros: 4
Status:
INTEGER OPTIMAL
Objective: obj = 18.5 (MINimum)
No. Row name
Activity
------ -----------------------1 vitaminas
32
2 proteinas
40
No. Column name
Activity
------ -----------------------1 x1
*
2
2 x2
*
5

Lower bound
------------32
36
Lower bound
------------0
0

Introdução à Otimização,

GLPK

Formato LP

Formato

Utilizando o GLPK

13 / 30

Formato MathProg

MathProg

Notas

Formato de mais alto nível, incluindo abstrações:
Comandos
Conjuntos
Parâmetros

Facilita a geração de problemas grandes e complexos
Permite a separação entre o modelo e os dados

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

Formato MathProg

Resolvendo a Dieta, versão

MathProg

Notas

Dieta.mod

§

14 / 30

¤

/∗ n u t r i e n t e s ∗/
set A;
/∗ a l i m e n t o s ∗/
param r {N} ;
/∗ r e q u e r i m e n t o d i a r i o p o r n u t r i e n t e ∗/
param v {A, N} ; / ∗ v a l o r q u e um a l i m e n t o o f e r e c e
de um n u t r i e n t e ∗ /
param c {A} ; / ∗ c u s t o u n i t . de c a d a a l i m e n t o ∗ /
N;

set

x { a i n A} = 0 ;
/ ∗ r e a i s do a l i m e n t o a q u e devem s e r comprados ∗ /

var

n u t r i r {n i n N} : sum{ a i n A} v [ a , n ] ∗ x [ a ] = r [ n ] ;
s a t i s f a z e r n e c e s s i d a d e de n u t r i e n t e n ∗ /

s.t.

/∗

minimize

¦

c u s t o : sum{ a i n A} c [ a ]

∗

x[a ];

Introdução à Otimização,

/∗ c o n t a

∗/

Utilizando o GLPK

¥

15 / 30
GLPK

Formato LP

Formato MathProg

Resolvendo a Dieta, versão
Dieta.dat (parte 1/2)

§
data

MathProg

¤

;

param

: N :

r :=

m i l h a r e s ∗/
∗/
Calcio
24 / ∗ gramas ∗ /
Ferro
33 / ∗ m i l i g r a m a s ∗ /
;
s e t A := T r i g o Q u e i j o F i g a d o Salmao E s p i n a f r e ;
param v d e f a u l t 0
:
Calorias
Proteinas
Calcio
F e r r o :=
Trigo
44 . 7
30
2 .0
20
Queijo
7 .4
44
16 . 4
19
Figado
2 .2
33
.2
80
Salmao
5 .8
70
6 .8
45
Espinafre
1 .1
10
9 .0
138
;
( continua )
Calorias

Proteinas

3 /∗

70 / ∗ gramas

¦

Introdução à Otimização,

GLPK

Formato LP

param

:

16 / 30

MathProg

Dieta.dat (parte 2/2)

§

Notas

¤

c :=
Trigo

0 .9

Queijo

1 .5

Figado

2 .1

Salmao

2 .4

Espinafre

2 .2

;

¥

Introdução à Otimização,

GLPK

Utilizando o GLPK

¥

Formato MathProg

Resolvendo a Dieta, versão

¦

Notas

Formato LP

Resolvendo a Dieta, versão

Utilizando o GLPK

17 / 30

Formato MathProg

MathProg

Notas

Comando
glpsol -m dieta.mod -d dieta.dat -o dietaSol.txt

Introdução à Otimização,

Utilizando o GLPK

18 / 30
GLPK

Formato LP

Formato MathProg

Comando

set

Notas

(1/2)

§

¤
/∗ d e c l a r a

set

I;

set

I := 1 . . 1 0 ;

c o n j u n t o que s e r a informado

d e p o i s ∗/

/ ∗ d e c l a r a um c o n j u n t o
p r e e n c h e n d o com num. de 1 a 10 ∗ /

s e t A := T r i g o Q u e i j o F i g a d o Salmao E s p i n a f r e ;
/ ∗ d e c l a r a e i n f o r m a e l e m e n t o s de um c o n j u n t o ∗ /
set

Cidades ;

C a p i t a i s within C i d a d e s ;
/∗ c o n j u n t o c a p i t a i s f i c a r e s t r i t o
s u b c o n j u n t o de c i d a d e s ∗ /
set

a s e r um

¦

¥

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

Formato MathProg

Comando

set

Notas

(2/2)

§

¤

s e t C{1 . . m } ;
/ ∗ c o n j u n t o de m c o n j u n t o s ∗ /
s e t C [ 1 ] := 1 14 3 ;
s e t C [ 2 ] := 5 9 25 1 8 ;
...
/ ∗ p r e e n c h i m e n t o de C ∗ /

¦

¥

Introdução à Otimização,

GLPK

Formato LP

Comando

Utilizando o GLPK

20 / 30

Formato MathProg

param

Notas

(1/2)

§
param

19 / 30

¤
n;

/∗ p a r a m e t r o q u e s e r a i n f o r m a d o

d e p o i s ∗/

c ,  0;
/∗ p a r a m e t r o q u e s e r a i n f o r m a d o
d e v e s e r p o s i t i v o ∗/

depois e

param

n , integer ,  0;
/∗ p a r a m e t r o q u e s e r a i n f o r m a d o d e p o i s e
d e v e s e r p o s i t i v o e i n t e i r o ∗/

param

¦

Introdução à Otimização,

¥

Utilizando o GLPK

21 / 30
GLPK

Formato LP

Comando

Formato MathProg

param

Notas

(2/2)

§

¤

c {A} ;
/∗ p a r a m e t r o q u e d e v e s e r i n f o r m a d o p a r a ca da
e l e m e n t o do c o n j u n t o A ∗ /

param

param

:

c :=
elementoDeA1

valorDeCparaA1

elementoDeA2

valorDeCparaA2

...

;
/ ∗ v a l o r do p a r a m e t r o c p a r a c a d a e l e m e n t de A ∗ /

¦

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

Comando

¥

22 / 30

Formato MathProg

var

Notas

§

¤
x = 0 ;

var

/ ∗ uma v a r i a v e l

positiva

∗/

x { I , J } , i n t e g e r , = 0 ;
/ ∗ c r i a uma v a r i a v e l x p a r a c a d a p a r ( i , j ) de I e J ,
v a r i a v e l i d e n t i f i c a d a p o r x [ i , j ] ∗/

var

z { i i n I , j i n J } = i+j ;
/ ∗ c r i a uma v a r i a v e l z p a r a c a d a p a r ( i , j ) de I e J ,
v a r i a v e l i d e n t i f i c a d a por z [ i , j ] ,
c a d a v a r i a v e l p o d e a s s u m i r v a l o r minimo i+j ∗ /

var

¦

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

23 / 30

Formato MathProg

Comando de Adição de Restrições:

s.t.

§

Notas
¤

s.t.

/∗

¥

r:

x + y + z , = 0 , = 1 ;

r e s t r i c a o com nome r , r e s t r i n g i n d o o s o m a t o r i o
de x + y + z p a r a o i n t e r v a l o [ 0 , 1 ] ∗ /

s . t . c a p a c i d a d e : sum{ i i n I } p [ i ] ∗ x [ i ] = c ;
/ ∗ uma r e s t r i c a o g e r a d a s o b r e o s o m a t o r i o da
x [ i ] m u l t i p l i c a n d o uma c o n s t a n d e p [ i ] ∗ /
s.t.

variavel

e s t o q u e F i n a l {p i n P } :
e s t o q u e [ 1 2 , p ] + compras [ 1 2 , p ]

/ ∗ uma r e s t r i c a o

¦

sera

− v e n d a s [ 1 2 , p ] = 5 0 0 ;
g e r a d a p a r a cada p r o d u t o p ∗/

Introdução à Otimização,

Utilizando o GLPK

¥

24 / 30
GLPK

Formato LP

Formato MathProg

Exemplo: Problema da Mochila - Modelo

§

Notas
¤

param

n,

param

c;

itens

∗/

/∗ c a p a c i d a d e ∗/

I := 1 . . n ;

set

/ ∗ numero de

integer ,  0;

param

/∗ l u c r o ∗/

l {I };

param

/∗ i t e m s ∗/

p{ I } ;

/∗ p e s o ∗/

x{ I } b i n a r y ;
/∗ 1 s e i n c l u i r , 0 c a s o

var

maximize

l u c r o : sum{ i

c a p a c i d a d e : sum{ i

s.t.

¦

c o n t r a r i o ∗/

in
in

I}

l [ i ]∗x [ i ] ;

I } p [ i ] ∗ x [ i ] = c ;

Introdução à Otimização,

GLPK

Formato LP

¥

Utilizando o GLPK

25 / 30

Formato MathProg

Exemplo: Problema da Mochila - Dados

§

Notas

¤

data

;

param

n:=

7;

param

c :=

10;

param

l

param

p := 1 3 , 2 4 , 3 1 , 4 1 ,

:= 1 7 , 2 7 , 3 2 , 4 1 ,
5 5, 6 5, 7
5 3, 6 3, 7

¦

8;
6;

¥

Introdução à Otimização,

GLPK

Formato LP

Utilizando o GLPK

26 / 30

Formato MathProg

O Problema da Alocação Generalizada

Notas

Denição

Temos um conjuntos de tarefas a realizar e um conjunto de
agentes que podem realizá-las.
Cada agente tem uma determinada habilidade para cada tarefa,
inuenciando no tempo que o mesmo leva para concluir a tarefa
e também determinando o custo do mesmo realizar aquela
tarefa. Além disso, os agentes tem uma capacidade limitada.
Deve-se determinar quais agentes farão cada tarefa respeitando
suas capacidades e minimizando o custo total.

Introdução à Otimização,

Utilizando o GLPK

27 / 30
GLPK

Formato LP

Formato MathProg

Problema da Alocação Generalizada Modelo

Notas

(1/2)

§

¤

/∗ n
param m, i n t e g e r ,  0 ; / ∗ m
s e t J := 1 . . n ;
/∗ c o n j u n t o
s e t I := 1 . . m ;
/∗ c o n j u n t o
param a { i i n I , j i n J } , =
param

n,

param

b{ i

in

param

c{ i

in

t a r e f a s ∗/
a g e n t e s ∗/
de t a r e f a s ∗ /
de a g e n t e s ∗ /
0 ; /∗ r e c u r s o s q u e o a g . i
g a s t a p a r a t a r e f a j ∗/
I } , = 0 ;
/ ∗ c a p a c i d a d e em
r e c u r s o s do a g . i ∗ /
I , j i n J } , = 0 ; / ∗ c u s t o do a g e n t e i
f a z e r t a r e f a j ∗/

integer ,  0;

¦

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

¥

28 / 30

Formato MathProg

Problema da Alocação Generalizada Modelo

§
var

Notas

(2/2)

¤
x{ i

I ,

in

j

/∗ x [ i , j ] = 1 :

J} ,

in

binary ;

agente

i

s . t . p r o c e s s a r { j in J } :
/∗ cada t a r e f a d e v e s e r

faz

tarefa

j ∗/

sum{

i in I } x [ i , j ] = 1 ;
p r o c e s s a d a p o r um a g e n t e ∗ /

s . t . l i m { i i n I } : sum{ j i n J } a [ i , j ] ∗ x [ i , j ] = b [ i ] ;
/ ∗ c a p a c i d a d e do a g e n t e ∗ /
minimize

/∗ a c h a r

¦

o b j : sum{ i

in I , j in J} c [ i , j ] ∗ x [ i , j ] ;
a l o c a c a o mais b a r a t a ∗ /

Introdução à Otimização,

GLPK

Utilizando o GLPK

Formato LP

¥

29 / 30

Formato MathProg

Problema da Alocação Generalizada -

Notas

Dados

§

¤

data ;

param

m :=

5;

param

n

:=

15;

a

:

param

3

4

10

11

12

15

14

23

8

16

8

25

9

17

25

15

10

8

24

15

7

23

22

11

11

12

10

17

16

7

16

10

18

22

3

21

20

6

22

14

11

19

16

4

20

11

8

14

9

5

6

19

19

7

6

6

13

9

18

5

param

2

8

2

param

1

1

8

13

13

13

10

20

25

16

16

17

10

10

5

12

23

;

1

36 ,

:=

b

:=

c

:

2

34 ,

5

24

3

6

10

38 ,

7

24

4

8

9

27 ,

9

21

14

5

11

13

14

15

:=

33;

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

1

17

21

22

18

24

15

20

18

19

18

16

22

24

24

16

2

23

16

21

16

17

16

19

25

18

21

17

15

25

17

24

3

16

20

16

25

24

16

17

19

19

18

20

16

17

21

24

4

19

19

22

22

20

16

19

17

21

19

25

23

25

25

25

5

18

19

15

15

21

25

16

16

23

15

22

17

19

22

24

;

end ;

¦

¥
Introdução à Otimização,

Utilizando o GLPK

30 / 30

Contenu connexe

Dernier

aula de bioquímica bioquímica dos carboidratos.ppt
aula de bioquímica bioquímica dos carboidratos.pptaula de bioquímica bioquímica dos carboidratos.ppt
aula de bioquímica bioquímica dos carboidratos.pptssuser2b53fe
 
apostila projeto de vida 2 ano ensino médio
apostila projeto de vida 2 ano ensino médioapostila projeto de vida 2 ano ensino médio
apostila projeto de vida 2 ano ensino médiorosenilrucks
 
Apresentação em Powerpoint do Bioma Catinga.pptx
Apresentação em Powerpoint do Bioma Catinga.pptxApresentação em Powerpoint do Bioma Catinga.pptx
Apresentação em Powerpoint do Bioma Catinga.pptxLusGlissonGud
 
Considere a seguinte situação fictícia: Durante uma reunião de equipe em uma...
Considere a seguinte situação fictícia:  Durante uma reunião de equipe em uma...Considere a seguinte situação fictícia:  Durante uma reunião de equipe em uma...
Considere a seguinte situação fictícia: Durante uma reunião de equipe em uma...azulassessoria9
 
planejamento_estrategico_-_gestao_2021-2024_16015654.pdf
planejamento_estrategico_-_gestao_2021-2024_16015654.pdfplanejamento_estrategico_-_gestao_2021-2024_16015654.pdf
planejamento_estrategico_-_gestao_2021-2024_16015654.pdfmaurocesarpaesalmeid
 
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptx
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptxSlides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptx
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptxLuizHenriquedeAlmeid6
 
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...HELENO FAVACHO
 
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdf
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdfPROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdf
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdfHELENO FAVACHO
 
Construção (C)erta - Nós Propomos! Sertã
Construção (C)erta - Nós Propomos! SertãConstrução (C)erta - Nós Propomos! Sertã
Construção (C)erta - Nós Propomos! SertãIlda Bicacro
 
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdf
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdfPROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdf
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdfHELENO FAVACHO
 
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de..."É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...Rosalina Simão Nunes
 
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdf
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdfPROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdf
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdfHELENO FAVACHO
 
Nós Propomos! " Pinhais limpos, mundo saudável"
Nós Propomos! " Pinhais limpos, mundo saudável"Nós Propomos! " Pinhais limpos, mundo saudável"
Nós Propomos! " Pinhais limpos, mundo saudável"Ilda Bicacro
 
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...azulassessoria9
 
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdf
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdfProjeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdf
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdfHELENO FAVACHO
 
Revolução russa e mexicana. Slides explicativos e atividades
Revolução russa e mexicana. Slides explicativos e atividadesRevolução russa e mexicana. Slides explicativos e atividades
Revolução russa e mexicana. Slides explicativos e atividadesFabianeMartins35
 
Currículo - Ícaro Kleisson - Tutor acadêmico.pdf
Currículo - Ícaro Kleisson - Tutor acadêmico.pdfCurrículo - Ícaro Kleisson - Tutor acadêmico.pdf
Currículo - Ícaro Kleisson - Tutor acadêmico.pdfTutor de matemática Ícaro
 
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...azulassessoria9
 
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEM
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEMPRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEM
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEMHELENO FAVACHO
 

Dernier (20)

aula de bioquímica bioquímica dos carboidratos.ppt
aula de bioquímica bioquímica dos carboidratos.pptaula de bioquímica bioquímica dos carboidratos.ppt
aula de bioquímica bioquímica dos carboidratos.ppt
 
apostila projeto de vida 2 ano ensino médio
apostila projeto de vida 2 ano ensino médioapostila projeto de vida 2 ano ensino médio
apostila projeto de vida 2 ano ensino médio
 
Apresentação em Powerpoint do Bioma Catinga.pptx
Apresentação em Powerpoint do Bioma Catinga.pptxApresentação em Powerpoint do Bioma Catinga.pptx
Apresentação em Powerpoint do Bioma Catinga.pptx
 
Considere a seguinte situação fictícia: Durante uma reunião de equipe em uma...
Considere a seguinte situação fictícia:  Durante uma reunião de equipe em uma...Considere a seguinte situação fictícia:  Durante uma reunião de equipe em uma...
Considere a seguinte situação fictícia: Durante uma reunião de equipe em uma...
 
planejamento_estrategico_-_gestao_2021-2024_16015654.pdf
planejamento_estrategico_-_gestao_2021-2024_16015654.pdfplanejamento_estrategico_-_gestao_2021-2024_16015654.pdf
planejamento_estrategico_-_gestao_2021-2024_16015654.pdf
 
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptx
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptxSlides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptx
Slides Lição 05, Central Gospel, A Grande Tribulação, 1Tr24.pptx
 
Aula sobre o Imperialismo Europeu no século XIX
Aula sobre o Imperialismo Europeu no século XIXAula sobre o Imperialismo Europeu no século XIX
Aula sobre o Imperialismo Europeu no século XIX
 
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...
PROJETO DE EXTENSÃO I - TECNOLOGIA DA INFORMAÇÃO Relatório Final de Atividade...
 
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdf
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdfPROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdf
PROJETO DE EXTENÇÃO - GESTÃO DE RECURSOS HUMANOS.pdf
 
Construção (C)erta - Nós Propomos! Sertã
Construção (C)erta - Nós Propomos! SertãConstrução (C)erta - Nós Propomos! Sertã
Construção (C)erta - Nós Propomos! Sertã
 
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdf
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdfPROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdf
PROJETO DE EXTENSÃO I - SERVIÇOS JURÍDICOS, CARTORÁRIOS E NOTARIAIS.pdf
 
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de..."É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...
"É melhor praticar para a nota" - Como avaliar comportamentos em contextos de...
 
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdf
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdfPROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdf
PROJETO DE EXTENSÃO - EDUCAÇÃO FÍSICA BACHARELADO.pdf
 
Nós Propomos! " Pinhais limpos, mundo saudável"
Nós Propomos! " Pinhais limpos, mundo saudável"Nós Propomos! " Pinhais limpos, mundo saudável"
Nós Propomos! " Pinhais limpos, mundo saudável"
 
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: COMUNICAÇÃO ASSERTIVA E INTERPESS...
 
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdf
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdfProjeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdf
Projeto_de_Extensão_Agronomia_adquira_ja_(91)_98764-0830.pdf
 
Revolução russa e mexicana. Slides explicativos e atividades
Revolução russa e mexicana. Slides explicativos e atividadesRevolução russa e mexicana. Slides explicativos e atividades
Revolução russa e mexicana. Slides explicativos e atividades
 
Currículo - Ícaro Kleisson - Tutor acadêmico.pdf
Currículo - Ícaro Kleisson - Tutor acadêmico.pdfCurrículo - Ícaro Kleisson - Tutor acadêmico.pdf
Currículo - Ícaro Kleisson - Tutor acadêmico.pdf
 
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...
PROVA - ESTUDO CONTEMPORÂNEO E TRANSVERSAL: LEITURA DE IMAGENS, GRÁFICOS E MA...
 
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEM
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEMPRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEM
PRÁTICAS PEDAGÓGICAS GESTÃO DA APRENDIZAGEM
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

GLPK: Otimização usando formatos LP e MathProg

  • 1. GLPK Formato LP Formato MathProg Notas Introdução à Otimização Utilizando o GLPK Haroldo Gambini Santos Universidade Federal de Ouro Preto 29 de março de 2011 Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 1 / 30 Formato MathProg Conteúdo 1 GLPK 2 Formato LP 3 Notas Formato MathProg Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 2 / 30 Formato MathProg GLPK Notas GNU Linear Programming Kit resolvedor de problemas lineares, incluindo problemas de programação inteira código aberto, disponível gratuitamente farta documentação Introdução à Otimização, Utilizando o GLPK 3 / 30
  • 2. GLPK Formato LP Formato MathProg GLPK Notas Instalação Windows: http://glpklabw.sourceforge.net/ Linux (debian/ubuntu e derivadas): sudo apt-get install glpk Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 4 / 30 Formato MathProg GLPK Notas Obtendo Ajuda Pacote disponível em: http://www.gnu.org/software/glpk/ doc) examples) Manuais em PDF (diretório Exemplos (diretório Lista de Discussão: help-glpk@gnu.org Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 5 / 30 Formato MathProg Introdução Notas Formatos conhecidos para entrada de programas lineares: MPS Mathematical Programming System : padrão da indústria pouco intuitivo, confuso e com limitações LP CPLEX LP le format : padrão criado para uso com o resolvedor CPLEX mais fácil e prático do que o formato MPS aceito nos principais resolvedores modernos arquivos podem ser convertidos para MPS Introdução à Otimização, Utilizando o GLPK 6 / 30
  • 3. GLPK Formato LP Formato MathProg Formato LP Notas Componentes função objetivo restrições informações de variáveis limites variáveis inteiras genéricas variáveis binárias Introdução à Otimização, GLPK Utilizando o GLPK Formato LP 7 / 30 Formato MathProg Problema da Dieta Notas Dieta.lp § Minimize ¤ obj : 3 x1 + 2 . 5 x2 Subject to v i t a m i n a s : 6 x1 + 4 x2 = 32 p r o t e i n a s : 5 x1 + 6 x2 = 36 End ¦ ¥ Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 8 / 30 Formato MathProg Resolvendo Notas Comando glpsol --cpxlp dieta.lp -o sol.txt Problem: Rows: Columns: Non-zeros: Status: Objective: sol.txt 2 2 4 OPTIMAL obj = 17.75 (MINimum) No. Row name St Activity Lower bound Upper bound ------ ------------ -- ------------- ------------- ------------1 vitaminas NL 32 32 2 proteinas NL 36 36 No. -----1 2 Column name -----------x1 x2 St Activity Lower bound Upper bound -- ------------- ------------- ------------B 3 0 B 3.5 0 Introdução à Otimização, Utilizando o GLPK 9 / 30
  • 4. GLPK Formato LP Formato MathProg Limites e Integralidade Notas Podem ser especicadas restrições especícas sobre algumas variáveis Essas restrições são informadas após a seção das restrições normais e podem ser dos seguintes tipos: Restrição de limites - Seção Bounds: Subject to ... Bounds 0 = x1 = 40 2 = x4 = 3 Exemplo Limites Introdução à Otimização, GLPK Utilizando o GLPK Formato LP Limites e Integralidade 10 / 30 Formato MathProg Notas (cont.) Para variáveis para as quais não são permitidos valores fracionários temos as seções: General: variáveis inteiras de modo geral Binary: variáveis binárias que somente podem assumir valor zero ou um Exemplo Integralidade Subject to ... Binary x3 General x1 x2 Introdução à Otimização, GLPK Utilizando o GLPK Formato LP 11 / 30 Formato MathProg Problema da Dieta Notas DietaInt.lp § Minimize ¤ obj : 3 x1 + 2 . 5 x2 Subject to v i t a m i n a s : 6 x1 + 4 x2 = 32 p r o t e i n a s : 5 x1 + 6 x2 = 36 General x1 x2 End ¦ ¥ Introdução à Otimização, Utilizando o GLPK 12 / 30
  • 5. GLPK Formato LP Formato MathProg Nova Solução Notas sol.txt Problem: Rows: 2 Columns: 2 (2 integer, 0 binary) Non-zeros: 4 Status: INTEGER OPTIMAL Objective: obj = 18.5 (MINimum) No. Row name Activity ------ -----------------------1 vitaminas 32 2 proteinas 40 No. Column name Activity ------ -----------------------1 x1 * 2 2 x2 * 5 Lower bound ------------32 36 Lower bound ------------0 0 Introdução à Otimização, GLPK Formato LP Formato Utilizando o GLPK 13 / 30 Formato MathProg MathProg Notas Formato de mais alto nível, incluindo abstrações: Comandos Conjuntos Parâmetros Facilita a geração de problemas grandes e complexos Permite a separação entre o modelo e os dados Introdução à Otimização, GLPK Formato LP Utilizando o GLPK Formato MathProg Resolvendo a Dieta, versão MathProg Notas Dieta.mod § 14 / 30 ¤ /∗ n u t r i e n t e s ∗/ set A; /∗ a l i m e n t o s ∗/ param r {N} ; /∗ r e q u e r i m e n t o d i a r i o p o r n u t r i e n t e ∗/ param v {A, N} ; / ∗ v a l o r q u e um a l i m e n t o o f e r e c e de um n u t r i e n t e ∗ / param c {A} ; / ∗ c u s t o u n i t . de c a d a a l i m e n t o ∗ / N; set x { a i n A} = 0 ; / ∗ r e a i s do a l i m e n t o a q u e devem s e r comprados ∗ / var n u t r i r {n i n N} : sum{ a i n A} v [ a , n ] ∗ x [ a ] = r [ n ] ; s a t i s f a z e r n e c e s s i d a d e de n u t r i e n t e n ∗ / s.t. /∗ minimize ¦ c u s t o : sum{ a i n A} c [ a ] ∗ x[a ]; Introdução à Otimização, /∗ c o n t a ∗/ Utilizando o GLPK ¥ 15 / 30
  • 6. GLPK Formato LP Formato MathProg Resolvendo a Dieta, versão Dieta.dat (parte 1/2) § data MathProg ¤ ; param : N : r := m i l h a r e s ∗/ ∗/ Calcio 24 / ∗ gramas ∗ / Ferro 33 / ∗ m i l i g r a m a s ∗ / ; s e t A := T r i g o Q u e i j o F i g a d o Salmao E s p i n a f r e ; param v d e f a u l t 0 : Calorias Proteinas Calcio F e r r o := Trigo 44 . 7 30 2 .0 20 Queijo 7 .4 44 16 . 4 19 Figado 2 .2 33 .2 80 Salmao 5 .8 70 6 .8 45 Espinafre 1 .1 10 9 .0 138 ; ( continua ) Calorias Proteinas 3 /∗ 70 / ∗ gramas ¦ Introdução à Otimização, GLPK Formato LP param : 16 / 30 MathProg Dieta.dat (parte 2/2) § Notas ¤ c := Trigo 0 .9 Queijo 1 .5 Figado 2 .1 Salmao 2 .4 Espinafre 2 .2 ; ¥ Introdução à Otimização, GLPK Utilizando o GLPK ¥ Formato MathProg Resolvendo a Dieta, versão ¦ Notas Formato LP Resolvendo a Dieta, versão Utilizando o GLPK 17 / 30 Formato MathProg MathProg Notas Comando glpsol -m dieta.mod -d dieta.dat -o dietaSol.txt Introdução à Otimização, Utilizando o GLPK 18 / 30
  • 7. GLPK Formato LP Formato MathProg Comando set Notas (1/2) § ¤ /∗ d e c l a r a set I; set I := 1 . . 1 0 ; c o n j u n t o que s e r a informado d e p o i s ∗/ / ∗ d e c l a r a um c o n j u n t o p r e e n c h e n d o com num. de 1 a 10 ∗ / s e t A := T r i g o Q u e i j o F i g a d o Salmao E s p i n a f r e ; / ∗ d e c l a r a e i n f o r m a e l e m e n t o s de um c o n j u n t o ∗ / set Cidades ; C a p i t a i s within C i d a d e s ; /∗ c o n j u n t o c a p i t a i s f i c a r e s t r i t o s u b c o n j u n t o de c i d a d e s ∗ / set a s e r um ¦ ¥ Introdução à Otimização, GLPK Formato LP Utilizando o GLPK Formato MathProg Comando set Notas (2/2) § ¤ s e t C{1 . . m } ; / ∗ c o n j u n t o de m c o n j u n t o s ∗ / s e t C [ 1 ] := 1 14 3 ; s e t C [ 2 ] := 5 9 25 1 8 ; ... / ∗ p r e e n c h i m e n t o de C ∗ / ¦ ¥ Introdução à Otimização, GLPK Formato LP Comando Utilizando o GLPK 20 / 30 Formato MathProg param Notas (1/2) § param 19 / 30 ¤ n; /∗ p a r a m e t r o q u e s e r a i n f o r m a d o d e p o i s ∗/ c , 0; /∗ p a r a m e t r o q u e s e r a i n f o r m a d o d e v e s e r p o s i t i v o ∗/ depois e param n , integer , 0; /∗ p a r a m e t r o q u e s e r a i n f o r m a d o d e p o i s e d e v e s e r p o s i t i v o e i n t e i r o ∗/ param ¦ Introdução à Otimização, ¥ Utilizando o GLPK 21 / 30
  • 8. GLPK Formato LP Comando Formato MathProg param Notas (2/2) § ¤ c {A} ; /∗ p a r a m e t r o q u e d e v e s e r i n f o r m a d o p a r a ca da e l e m e n t o do c o n j u n t o A ∗ / param param : c := elementoDeA1 valorDeCparaA1 elementoDeA2 valorDeCparaA2 ... ; / ∗ v a l o r do p a r a m e t r o c p a r a c a d a e l e m e n t de A ∗ / ¦ Introdução à Otimização, GLPK Utilizando o GLPK Formato LP Comando ¥ 22 / 30 Formato MathProg var Notas § ¤ x = 0 ; var / ∗ uma v a r i a v e l positiva ∗/ x { I , J } , i n t e g e r , = 0 ; / ∗ c r i a uma v a r i a v e l x p a r a c a d a p a r ( i , j ) de I e J , v a r i a v e l i d e n t i f i c a d a p o r x [ i , j ] ∗/ var z { i i n I , j i n J } = i+j ; / ∗ c r i a uma v a r i a v e l z p a r a c a d a p a r ( i , j ) de I e J , v a r i a v e l i d e n t i f i c a d a por z [ i , j ] , c a d a v a r i a v e l p o d e a s s u m i r v a l o r minimo i+j ∗ / var ¦ Introdução à Otimização, GLPK Utilizando o GLPK Formato LP 23 / 30 Formato MathProg Comando de Adição de Restrições: s.t. § Notas ¤ s.t. /∗ ¥ r: x + y + z , = 0 , = 1 ; r e s t r i c a o com nome r , r e s t r i n g i n d o o s o m a t o r i o de x + y + z p a r a o i n t e r v a l o [ 0 , 1 ] ∗ / s . t . c a p a c i d a d e : sum{ i i n I } p [ i ] ∗ x [ i ] = c ; / ∗ uma r e s t r i c a o g e r a d a s o b r e o s o m a t o r i o da x [ i ] m u l t i p l i c a n d o uma c o n s t a n d e p [ i ] ∗ / s.t. variavel e s t o q u e F i n a l {p i n P } : e s t o q u e [ 1 2 , p ] + compras [ 1 2 , p ] / ∗ uma r e s t r i c a o ¦ sera − v e n d a s [ 1 2 , p ] = 5 0 0 ; g e r a d a p a r a cada p r o d u t o p ∗/ Introdução à Otimização, Utilizando o GLPK ¥ 24 / 30
  • 9. GLPK Formato LP Formato MathProg Exemplo: Problema da Mochila - Modelo § Notas ¤ param n, param c; itens ∗/ /∗ c a p a c i d a d e ∗/ I := 1 . . n ; set / ∗ numero de integer , 0; param /∗ l u c r o ∗/ l {I }; param /∗ i t e m s ∗/ p{ I } ; /∗ p e s o ∗/ x{ I } b i n a r y ; /∗ 1 s e i n c l u i r , 0 c a s o var maximize l u c r o : sum{ i c a p a c i d a d e : sum{ i s.t. ¦ c o n t r a r i o ∗/ in in I} l [ i ]∗x [ i ] ; I } p [ i ] ∗ x [ i ] = c ; Introdução à Otimização, GLPK Formato LP ¥ Utilizando o GLPK 25 / 30 Formato MathProg Exemplo: Problema da Mochila - Dados § Notas ¤ data ; param n:= 7; param c := 10; param l param p := 1 3 , 2 4 , 3 1 , 4 1 , := 1 7 , 2 7 , 3 2 , 4 1 , 5 5, 6 5, 7 5 3, 6 3, 7 ¦ 8; 6; ¥ Introdução à Otimização, GLPK Formato LP Utilizando o GLPK 26 / 30 Formato MathProg O Problema da Alocação Generalizada Notas Denição Temos um conjuntos de tarefas a realizar e um conjunto de agentes que podem realizá-las. Cada agente tem uma determinada habilidade para cada tarefa, inuenciando no tempo que o mesmo leva para concluir a tarefa e também determinando o custo do mesmo realizar aquela tarefa. Além disso, os agentes tem uma capacidade limitada. Deve-se determinar quais agentes farão cada tarefa respeitando suas capacidades e minimizando o custo total. Introdução à Otimização, Utilizando o GLPK 27 / 30
  • 10. GLPK Formato LP Formato MathProg Problema da Alocação Generalizada Modelo Notas (1/2) § ¤ /∗ n param m, i n t e g e r , 0 ; / ∗ m s e t J := 1 . . n ; /∗ c o n j u n t o s e t I := 1 . . m ; /∗ c o n j u n t o param a { i i n I , j i n J } , = param n, param b{ i in param c{ i in t a r e f a s ∗/ a g e n t e s ∗/ de t a r e f a s ∗ / de a g e n t e s ∗ / 0 ; /∗ r e c u r s o s q u e o a g . i g a s t a p a r a t a r e f a j ∗/ I } , = 0 ; / ∗ c a p a c i d a d e em r e c u r s o s do a g . i ∗ / I , j i n J } , = 0 ; / ∗ c u s t o do a g e n t e i f a z e r t a r e f a j ∗/ integer , 0; ¦ Introdução à Otimização, GLPK Utilizando o GLPK Formato LP ¥ 28 / 30 Formato MathProg Problema da Alocação Generalizada Modelo § var Notas (2/2) ¤ x{ i I , in j /∗ x [ i , j ] = 1 : J} , in binary ; agente i s . t . p r o c e s s a r { j in J } : /∗ cada t a r e f a d e v e s e r faz tarefa j ∗/ sum{ i in I } x [ i , j ] = 1 ; p r o c e s s a d a p o r um a g e n t e ∗ / s . t . l i m { i i n I } : sum{ j i n J } a [ i , j ] ∗ x [ i , j ] = b [ i ] ; / ∗ c a p a c i d a d e do a g e n t e ∗ / minimize /∗ a c h a r ¦ o b j : sum{ i in I , j in J} c [ i , j ] ∗ x [ i , j ] ; a l o c a c a o mais b a r a t a ∗ / Introdução à Otimização, GLPK Utilizando o GLPK Formato LP ¥ 29 / 30 Formato MathProg Problema da Alocação Generalizada - Notas Dados § ¤ data ; param m := 5; param n := 15; a : param 3 4 10 11 12 15 14 23 8 16 8 25 9 17 25 15 10 8 24 15 7 23 22 11 11 12 10 17 16 7 16 10 18 22 3 21 20 6 22 14 11 19 16 4 20 11 8 14 9 5 6 19 19 7 6 6 13 9 18 5 param 2 8 2 param 1 1 8 13 13 13 10 20 25 16 16 17 10 10 5 12 23 ; 1 36 , := b := c : 2 34 , 5 24 3 6 10 38 , 7 24 4 8 9 27 , 9 21 14 5 11 13 14 15 := 33; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 17 21 22 18 24 15 20 18 19 18 16 22 24 24 16 2 23 16 21 16 17 16 19 25 18 21 17 15 25 17 24 3 16 20 16 25 24 16 17 19 19 18 20 16 17 21 24 4 19 19 22 22 20 16 19 17 21 19 25 23 25 25 25 5 18 19 15 15 21 25 16 16 23 15 22 17 19 22 24 ; end ; ¦ ¥ Introdução à Otimização, Utilizando o GLPK 30 / 30