PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the...

40
PTC3420 - Programação Matemática Aplicada a Controle Exemplos de PL PTC - EPUSP Aula 2 - 2020 Agradecimento: Agradeço a Profa. Celma Ribeiro pelos arquivos latex do curso PRO-3341, usados na preparação das aulas desse curso. PTC-3420

Transcript of PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the...

Page 1: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

PTC3420 - Programação MatemáticaAplicada a Controle

Exemplos de PL

PTC - EPUSP

Aula 2 - 2020Agradecimento: Agradeço a Profa. Celma Ribeiro pelos arquivos latex do curso PRO-3341, usados

na preparação das aulas desse curso.

PTC-3420

Page 2: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Descrição Geral de um Problema deTransportes

Em geral, um problema de transportes é especificado pelasseguintes informações:

Um conjunto m de pontos de oferta (supply points) de ondeos bens são enviados;Um conjunto n de pontos de demanda (demand points) paraonde os bens são enviados;Para cada unidade produzida no ponto de oferta e enviadapara um ponto de demanda incorre uma variável de custo cij .

Seja,xij = número de unidades enviadas de i até j

então a formulação geral de um problema de transportes é:

minm∑i=1

n∑j=1

cijxij

PTC-3420

Page 3: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Descrição Geral de um Problema deTransportes

Se a capacidade máxima do ponto de oferta for si e a capacidademínima do ponto de demanda for dj , então temos as restrições:

n∑j=1

xij ≤ si (i = 1, 2, ...,m) (supply constraints)

m∑i=1

xij ≥ dj (j = 1, 2, ..., n) (demand constraints)

xij ≥ 0 (i = 1, 2, ..,m; j = 1, 2, ..., n)

PTC-3420

Page 4: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Descrição Geral de um Problema deTransportes

Se a seguinte condição se aplica a um problema, então ele é umproblema balanceado:

m∑i=1

si =n∑

j=1

dj

Veremos mais adiante o que fazer com problemas de transportesdesbalanceados.

PTC-3420

Page 5: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo 1: Formulando Problemas deTransportes

Material baseado no livro do Winston

Powerco possui três plantas geradoras de energia elétrica que satisfazemas necessidades de quatro cidades. A tabela abaixo apresenta acapacidade de cada planta e a demanda máxima de cada cidade (queocorrem simultaneamente) em kWh. O custo de enviar um 1 milhão dekWh para uma cidade depende da distância entre a planta e a cidade:

Formule um problema de programação linear que minimize o custode satisfazer a demanda das quatro cidades.

PTC-3420

Page 6: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Solução do Problema de Transportes

Sendo xi,j a variável de decisão da Powerco, para i = 1, 2, 3 ej = 1, 2, 3, 4, temos:

xij = milhões de kWh produzidos na planta ie consumidos na cidade j

Então o custo total para suprir a demanda é:

8x11 + 6x12 + 10x13 + 9x14 (Custo de envio da planta 1)+ 9x21 + 12x22 + 13x23 + 7x24 (Custo de envio da planta 2)+ 14x31 + 9x32 + 16x33 + 5x34 (Custo de envio da planta 3)

PTC-3420

Page 7: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Solução do Problema de Transportes

Powerco possui dois tipos de restrições. O total de potênciafornecida por cada planta não pode exceder a sua capacidade(supply constraint) e a demanda de cada cidade deve ser atendidapor completo (demand constraint). Portanto:

x11 + x12 + x13 + x14 ≤ 35

x21 + x22 + x23 + x24 ≤ 50

x31 + x32 + x33 + x34 ≤ 40

x11 + x21 + x31 ≥ 45

x12 + x22 + x32 ≥ 20

x13 + x23 + x33 ≥ 30

x14 + x24 + x34 ≥ 30Então,

min 8x11 + 6x12 + 10x13 + 9x14 + 9x21 + 12x22 + 13x23 + 7x24++14x31 + 9x32 + 16x33 + 5x34

PTC-3420

Page 8: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Matlab - linprog

Provide feedback about this page

linprogSolve linear programming problems

Equation

Finds the minimum of a problem specified by

f, x, b, beq, lb, and ub are vectors, and A and Aeq are matrices.

Syntax x = linprog(f,A,b)x = linprog(f,A,b,Aeq,beq)x = linprog(f,A,b,Aeq,beq,lb,ub)x = linprog(f,A,b,Aeq,beq,lb,ub,x0)x = linprog(f,A,b,Aeq,beq,lb,ub,x0,options)x = linprog(problem)[x,fval] = linprog(...)[x,fval,exitflag] = linprog(...)[x,fval,exitflag,output] = linprog(...)[x,fval,exitflag,output,lambda] = linprog(...)

Description

linprog solves linear programming problems.

x = linprog(f,A,b) solves min f'*x such that A*x ≤ b .

x = linprog(f,A,b,Aeq,beq) solves the problem above while additionallysatisfying the equality constraints Aeq*x = beq . Set A = [] and b = [] if noinequalities exist.

x = linprog(f,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds onthe design variables, x , so that the solution is always in the range lb ≤ x ≤ ub . Set Aeq = [] and beq = [] if no equalities exist.

x = linprog(f,A,b,Aeq,beq,lb,ub,x0) sets the starting point to x0 . Thisoption is only available with the medium-scale algorithm (the LargeScale option is setto 'off' using optimset ). The default large-scale algorithm and the simplexalgorithm ignore any starting point.

x = linprog(f,A,b,Aeq,beq,lb,ub,x0,options) minimizes with theoptimization options specified in the structure options . Use optimset to set theseoptions.

x = linprog(problem) finds the minimum for problem , where problem is astructure described in Input Arguments.

PTC-3420

Page 9: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Solução do Problema de TransportesA solução do problema de transportes será:

Z = 1020x12 = 10, x13 = 25, x21 = 45, x23 = 5, x32 = 10, x34 = 30

PTC-3420

Page 10: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Balanceando um Problema de TransportesSe um problema for desbalanceado, com oferta superior a demanda,podemos definir um ponto de demanda dummy com demandaigual ao excesso de oferta. Como envios para o ponto dummy nãosão envios reais, assume-se custos nulos.

PTC-3420

Page 11: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Balanceando um Problema de Transportes

Se o problema de transportes oferta < demanda o problema éinviável.pode ser conveniente deixar parte da demanda nãoatendida. Porém, nesse caso, associa-se uma penalidade àdemanda não atendida.

PTC-3420

Page 12: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Modelos de Rastreamento em Carteiras deInvestimentoSuponha que se tenha uma série histórica com T dados sobre umíndice que se deseja rastrear, bem como de p ativos básicos quecompõem esse índice. Sendo y o vetor T -dimensional com asobservações do índice que se deseja rastrear, e Γ a matriz T × pcom T observações dos p ativos básicos que se considera, tem-se,

PTC-3420

Page 13: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

y =

y(1)...

y(T )

=

PB(1)...

PB(T )

Γ =

R1(1) . . . Rp(1)...

. . ....

R1(T ) . . . Rp(T )

.

PTC-3420

Page 14: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Modelos de RastreamentoDeseja-se encontrar a composição da carteira que minimize adiferença entre seus retornos e os retornos do benchmark. Oproblema consiste em minimizar o seguinte erro err:

err = y − Γω.

O vetor ω, que dá a composição da carteira, é escolhido segundo aseguinte minimização de funções objetivo que serão apresentadas aseguir.

PTC-3420

Page 15: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo 2Considere os dados de 2 fundos, mercado, e título público em 4anos. Formule e resolva o problema de rastrear a carteira demercado com os 2 fundos e título público considerando o caso seme com restrições a posições vendidas.

Tabela: Dados dos fundos, mercado e título público

Ano Fundo 1 Fundo 2 Título Público Mercado1 35,0% 20,0% 14,0% 32,0%2 -5,0% 8,0% 13,5% -2,0%3 28,0% 18,0% 13,0% 26,0%4 -4,0% 7,0% 12,0% -3,0%

PTC-3420

Page 16: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo

Γ =

35, 0% 20, 0% 14, 0%−5, 0% 8, 0% 13, 5%28, 0% 18, 0% 13, 0%−4, 0% 7, 0% 12, 0%

y =

32, 0%−2, 0%26, 0%−3, 0%

PTC-3420

Page 17: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Rastreamento por Programação Linear -MODELO MAD:Deseja-se minimizar os desvios absolutos da média (MAD) Osseguintes modelos de rastreamento foram propostos em [Rudolf]:

min e′(∣∣y − Γω

∣∣)sujeito aω′e = 1,

ω ≥ 0,

ω ∈ Rp,

(1)

PTC-3420

Page 18: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

em que ∣∣y − Γω∣∣ =

∣∣y(1)− Γ(1)ω

∣∣...∣∣y(T )− Γ(T )ω

∣∣ ,

eΓ(t) =

(R1(t) . . . Rp(t)

).

PTC-3420

Page 19: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

MODELO Min-Max:deseja-se minimizar o maior desvio entre a carteira de referência e acarteira (Min-Max):

minω

maxt

∣∣y(t)− Γ(t)ω∣∣

sujeito aω′e = 1,

ω ≥ 0,

ω ∈ Rp.

(2)

Duas variações do modelo MAD e Min-Max ocorrem quando sepenaliza apenas o caso em que o retorno está abaixo da carteira dereferência (MADD e o DMin-Max).

PTC-3420

Page 20: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

MODELO MADD:

min e′((y − Γω)+

)sujeito aω′e = 1,

ω ≥ 0,

ω ∈ Rn,

(3)

PTC-3420

Page 21: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

em que

(y − Γω)+ =

(y(1)− Γ(1)ω)+

...(y(T )− Γ(T )ω)+

e

(x)+ =

{x se x ≥ 0

0 se x < 0.

PTC-3420

Page 22: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

MODELO DMin-Max:

minω

maxt

(y(t)− Γ(t)ω)+

sujeito aω′e = 1,

ω ≥ 0,

ω ∈ Rp.

(4)

PTC-3420

Page 23: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Os Problemas (1), (2), (3) e (4) são formulados como programaçãolinear (P.L.). Inicia-se pelo Problema (2). Pode-se reescrevê-locomo

min zsujeito az ≥ y(t)− Γ(t)ω,

− z ≤ y(t)− Γ(t)ω,

ω′e = 1,

ω ∈ Rp, t = 1, . . . , T.

PTC-3420

Page 24: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo - Modelo Min-Max

ωopt =

0, 83330, 1667

0

zopt = 0, 83%.

Tabela: Erro

Ano Erro (Mercado-Portolio)1 -0,5%2 0,83%3 -0,33%4 -0,83%

Erro Total = 2, 5%PTC-3420

Page 25: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

No caso (4), a única restrição relevante é z ≥ y(t)− Γ(t)ω (poisnão importa se z ≤ y(t)− Γ(t)ω). Logo, o problema pode serreescrito como P.L. da seguinte forma:

min zsujeito az ≥ y(t)− Γ(t)ω,

ω′e = 1,

ω ∈ Rp, t = 1, . . . , T.

PTC-3420

Page 26: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo - Modelo DMin-Max

ωopt =

0, 81360, 11860, 0678

zopt = 0, 2%.

Tabela: Erro

Ano Erro (Mercado-Portolio)1 0,2%2 0,2%3 0,2%4 -1,39%

Erro Total = 2, 0%PTC-3420

Page 27: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Para o caso (1), sendo

z+t = (y(t)− Γ(t)ω)+ , z−t = (Γ(t)ω − y(t))+ ,

tem-se que ∣∣y(t)− Γ(t)ω∣∣ = z+t + z−t .

Note que

Γ(t)ω − y(t) ≥ 0⇒ z−t = Γ(t)ω − y(t)

Γ(t)ω − y(t) ≤ 0⇒ z+t = y(t)− Γ(t)ω

e que z−t × z+t = 0. Logo,

y(t)− Γ(t)ω = z+t − z−t

PTC-3420

Page 28: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

e o problema de P.L. pode ser escrito como

minT∑t=i

(z+t + z−t

)sujeito ay(t)− Γ(t)ω = z+t − z

−t , t = 1, . . . , T

ω′e = 1,

z+t ≥ 0, z−t ≥ 0, t = 1, . . . , T,

ω ∈ Rp.

PTC-3420

Page 29: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo - Modelo Mad

ωopt =

0, 80, 20

Tabela: Erro

Ano Erro (Mercado-Portolio)1 0%2 0,4%3 0%4 -1,2%

Erro Total = 1, 6%PTC-3420

Page 30: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Para o caso (2), impõem-se restrições apenas quando o retornoestá abaixo do retorno da carteira de referência, isto é, z+t .Conseqüentemente, o problema de P.L. é

minT∑t=1

z+t

sujeito ay(t)− Γ(t)ω ≤ z+t , t = 1, . . . , T

ω′e = 1,

z+t ≥ 0, t = 1, . . . , T,

ω ∈ Rp.

PTC-3420

Page 31: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exemplo - Modelo DMadSolução igual ao caso anterior.

ωopt =

0, 80, 20

Tabela: Erro

Ano Erro (Mercado-Portolio)1 0%2 0,4%3 0%4 -1,2%

PTC-3420

Page 32: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exercício 3 - Problema de DesignaçãoTrês pessoas devem realizar três tarefas distintas, sendo que cadapessoa apresenta uma habilidade para realizar cada uma das tarefas.Cada tarefa é realizada por uma única pessoa e cada pessoa realizauma única tarefa. Os dados são apresentados na tabela abaixo.

T1 T2 T3P1 13 10 9P2 12 5 11P3 8 6 10

Formular um problema de PL para distribuir as atividades tal que ahabilidade total seja máxima.

PTC-3420

Page 33: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

PTC-3420

Page 34: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exercício 4 - Problema da misturaUma metalúrgica deseja maximizar sua receita bruta. A tabela a seguirilustra a quantidade (proporção) de cada material na mistura para aobtenção das ligas passíveis de fabricação, assim como a disponibilidadede cada matéria prima (em toneladas) e os preços de venda por toneladade cada liga. Construa o modelo que minimiza custos

Liga 1 Liga 2 Disponibilidadeton

Cobre 0,50 0,20 16Zinco 0,25 0,3 11Chumbo 0,25 0,5 15Preço (R$) 3000 5000

xj : quantidade produzida da liga j (em toneladas)

PTC-3420

Page 35: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exercício 4 - Problema da misturaUma metalúrgica deseja maximizar sua receita bruta. A tabela a seguirilustra a quantidade (proporção) de cada material na mistura para aobtenção das ligas passíveis de fabricação, assim como a disponibilidadede cada matéria prima (em toneladas) e os preços de venda por toneladade cada liga. Construa o modelo que minimiza custos

Liga 1 Liga 2 Disponibilidadeton

Cobre 0,50 0,20 16Zinco 0,25 0,3 11Chumbo 0,25 0,5 15Preço (R$) 3000 5000

xj : quantidade produzida da liga j (em toneladas)

PTC-3420

Page 36: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

PTC-3420

Page 37: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exercício 5Determinar coeficientes α, β, γ, δ de polinômios de terceiro grauy(x) = αx3 + βx2 + γx+ δ que melhor se ajustam às observações(xi, yi) obtidas em um experimento científico. O erro (valorabsoluto) de uma observação é expresso por |y(xi)− yi|.

a. minimizar o erro máximob. minimizar o erro total

x -2 -1 0 1 2y -13 2 3 2 11

PTC-3420

Page 38: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

PTC-3420

Page 39: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

Exercício 6 - Fábrica de BrinquedosUma empresa de brinquedos fabrica 2 brinquedos de madeira: soldados etrens. Um soldado é vendido por $ 27 e custa de material $ 10, e de mãode obra $ 14. Um trem é vendido por $ 21 e custa, de material, $ 9, e demão de obra $ 10. A mão de obra para os 2 brinquedos envolvecarpintaria e acabamento. Um soldado exige 2 hs de acabamento e 1hora de carpintaria, e um trem exige 1 h de acabamento e 1 h decarpintaria. Cada semana a empresa tem disponível 100 hs deacabamento e 80 hs de carpintaria, e todo material que necessita para aprodução dos brinquedos. A demanda por trens é ilimitada, mas nomáximo 40 soldados são comprados por semana. Como a empresa podemaximizar sue lucro semanal?

Soldado Trem Disponibilidade (hs)Carpintaria 1 1 80Acabamento 2 1 100Limite 40 -Lucro p/ unidade $ 3 $ 2

PTC-3420

Page 40: PTC3420 - Programação Matemática Aplicada a Controle · the design variables, x, so that the solution is always in the range lb £ x £ ub . Set Aeq = [] and beq = [] if no equalities

PTC-3420