LP real world - cpb-us-w2.wpmucdn.com

89
NLP: Examples A. J. Conejo, R. Sioshansi, 2016

Transcript of LP real world - cpb-us-w2.wpmucdn.com

Page 1: LP real world - cpb-us-w2.wpmucdn.com

NLP: Examples

A. J. Conejo, R. Sioshansi, 2016

Page 2: LP real world - cpb-us-w2.wpmucdn.com

What

July 2, 2017 A. J. Conejo, R. Sioshansi 2

Page 3: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 3

Page 4: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 4

Page 5: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 5

Page 6: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 6

Page 7: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 7

Page 8: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 8

Page 9: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 9

Page 10: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 10

Page 11: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 11

Page 12: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 12

Page 13: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 13

r = -2:1/10:3;h = 0:1/10:4;[R,H] = meshgrid(r,h);F = 10.*pi.*R.^2.*H .- ...

2.*pi.*R.^2 .- ...(1/2).*pi.*R.^2.*H.*(pi.*R.^2 + 2.*pi.*R.*H);

figuresurf(R,H,F)

Page 14: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 14

Page 15: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 15

Page 16: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 16

scalars N /10/, c1 /2/, c2 /0.5/;variable z;positive variables r, h;r.l=1; h.l=1;equations of;of .. z =e= N*pi*h*r**2-c1*pi*r**2-c2*pi*h*(pi*r**2+2*pi*r*h)*r**2;model cyl /all/;solve cyl using nlp maximizing z;

Page 17: LP real world - cpb-us-w2.wpmucdn.com

Cylinder Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 17

LOWER LEVEL UPPER MARGINAL

---- VAR z -INF 12.174 +INF . ---- VAR r . 0.826 +INF EPS ---- VAR h . 1.721 +INF EPS

Page 18: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 18

Page 19: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 19

Page 20: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 20

Page 21: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 21

Page 22: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 22

Page 23: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 23

Page 24: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 24

Page 25: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 25

Page 26: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 26

Page 27: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 27

Page 28: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 28

scalars h /2/, w /3/;variable z;positive variables x, y;x.l=1; y.l=1;equations of, box;of .. z =e= sqrt(x**2+y**2);box .. y-w*y/x =g= h;model awning /all/;solve awning using nlp minimizing z;

Page 29: LP real world - cpb-us-w2.wpmucdn.com

Awning Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 29

LOWER LEVEL UPPER MARGINAL

---- VAR z -INF 7.023 +INF . ---- VAR x . 5.289 +INF . ---- VAR y . 4.621 +INF EPS

Page 30: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 30

Page 31: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 31

Page 32: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 32

Page 33: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 33

Page 34: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 34

Page 35: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 35

Page 36: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 36

Page 37: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 37

variable z;positive variables h, w, d;h.l=1; w.l=1; d.l=1;equations of, cardBoard;of .. z =e= h*w*d;cardBoard .. 2*w*h+2*h*d+6*w*d =l= 60;model box /all/;Option NLP = KNITRO;solve box using nlp maximizing z;

Page 38: LP real world - cpb-us-w2.wpmucdn.com

Packing-Box Problem

July 2, 2017 A. J. Conejo, R. Sioshansi 38

LOWER LEVEL UPPER MARGINAL

---- VAR z -INF 18.257 +INF . ---- VAR h . 5.477 +INF EPS ---- VAR w . 1.826 +INF -2.31E-11 ---- VAR d . 1.826 +INF -2.31E-11

Page 39: LP real world - cpb-us-w2.wpmucdn.com

Optimal power flow

July 2, 2017 A. J. Conejo 39

Page 40: LP real world - cpb-us-w2.wpmucdn.com

Optimal power flow

July 2, 2017 A. J. Conejo 40

Page 41: LP real world - cpb-us-w2.wpmucdn.com

Introduction

July 2, 2017 A. J. Conejo 41

Page 42: LP real world - cpb-us-w2.wpmucdn.com

Introduction

July 2, 2017 A. J. Conejo 42

Page 43: LP real world - cpb-us-w2.wpmucdn.com

Introduction

July 2, 2017 A. J. Conejo 43

We cannot guarantee this with a power flow

This is a security issue!

Page 44: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 44

Page 45: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 45

Page 46: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 46

Page 47: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 47

Page 48: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 48

Page 49: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 49

Page 50: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 50

Page 51: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 51

Page 52: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 52

Page 53: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 53

Page 54: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 54

Page 55: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 55

Page 56: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 56

Page 57: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 57

Page 58: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 58

Page 59: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 59

Page 60: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 60

Page 61: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 61

Page 62: LP real world - cpb-us-w2.wpmucdn.com

Formulation

July 2, 2017 A. J. Conejo 62

Page 63: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 63

Page 64: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 64

Page 65: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 65

Page 66: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 66

Page 67: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 67

Page 68: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 68

Page 69: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 69

Page 70: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 70

Page 71: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 71

Page 72: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 72

P-balance per node

Page 73: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 73

Q-balance per node

Page 74: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 74

Capacity limit per line

Page 75: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 75

Other limits

Page 76: LP real world - cpb-us-w2.wpmucdn.com

Just the math

July 2, 2017 A. J. Conejo, R. Sioshansi 76

Page 77: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 77

Page 78: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 78

Page 79: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 79

Page 80: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 80

Page 81: LP real world - cpb-us-w2.wpmucdn.com

Example

July 2, 2017 A. J. Conejo 81

Page 82: LP real world - cpb-us-w2.wpmucdn.com

GAMS code

July 2, 2017 A. J. Conejo 82

Page 83: LP real world - cpb-us-w2.wpmucdn.com

GAMS code

July 2, 2017 A. J. Conejo 83

Page 84: LP real world - cpb-us-w2.wpmucdn.com

GAMS code: simple

July 2, 2017 A. J. Conejo 84

parametersyl / 9.95037190209989/al / -1.47112767430373/;variablesz, p1, p2, q1, q2, v1, v2, v3, d1, d2;p1.lo = 0; p2.lo = 0;p1.up = 3; p2.up = 0.8;q1.lo = -2; q2.lo = -2;q1.up = 2; q2.up = 2;v1.lo = .95; v2.lo = .95; v3.lo = .95;v1.up = 1.1; v2.up = 1.1; v3.up = 1.1;d1.lo = -pi; d2.lo = -pi;d1.up = pi; d2.up = pi;v1.l=1; v2.l=1; v3.l=1;d1.l=0; d2.l=0;

Page 85: LP real world - cpb-us-w2.wpmucdn.com

GAMS code: simple

July 2, 2017 A. J. Conejo 85

equationsof, bp1, bp2, bp3, bq1, bq2, bq3, l12, l21, l13, l31, l23, l32;of.. z =e= 2*p1 + p2;bp1.. p1 =e= yl*cos(al)*(v1)**2-yl*v1*v2*cos(d1-d2-al)+

yl*cos(al)*(v1)**2-yl*v1*v3*cos(d1- 0-al);bp2.. p2 =e= yl*cos(al)*(v2)**2-yl*v2*v1*cos(d2-d1-al)+

yl*cos(al)*(v2)**2-yl*v2*v3*cos(d2- 0-al);bp3.. -0.8 =e= yl*cos(al)*(v3)**2-yl*v3*v1*cos( 0-d1-al)+

yl*cos(al)*(v3)**2-yl*v3*v2*cos( 0-d2-al);bq1.. q1 =e= -yl*sin(al)*(v1)**2-yl*v1*v2*sin(d1-d2-al)-

yl*sin(al)*(v1)**2-yl*v1*v3*sin(d1- 0-al);bq2.. q2 =e= -yl*sin(al)*(v2)**2-yl*v2*v1*sin(d2-d1-al)-

yl*sin(al)*(v2)**2-yl*v2*v3*sin(d2- 0-al);bq3.. -0.6 =e= -yl*sin(al)*(v3)**2-yl*v3*v1*sin( 0-d1-al)-

yl*sin(al)*(v3)**2-yl*v3*v2*sin( 0-d2-al);

Page 86: LP real world - cpb-us-w2.wpmucdn.com

GAMS code: simple

July 2, 2017 A. J. Conejo 86

l12.. sqrt(sqr(yl*cos(al)*(v1)**2-yl*v1*v2*cos(d1-d2-al))+sqr(-yl*sin(al)*(v1)**2-yl*v1*v2*sin(d1-d2-al))) =l= 0.25;

l21.. sqrt(sqr(yl*cos(al)*(v2)**2-yl*v2*v1*cos(d2-d1-al))+sqr(-yl*sin(al)*(v2)**2-yl*v2*v1*sin(d2-d1-al))) =l= 0.25;

l13.. sqrt(sqr(yl*cos(al)*(v1)**2-yl*v1*v3*cos(d1- 0-al))+sqr(-yl*sin(al)*(v1)**2-yl*v1*v3*sin(d1- 0-al))) =l= 2;

l31.. sqrt(sqr(yl*cos(al)*(v3)**2-yl*v3*v1*cos( 0-d1-al))+sqr(-yl*sin(al)*(v3)**2-yl*v3*v1*sin( 0-d1-al))) =l= 2;

l23.. sqrt(sqr(yl*cos(al)*(v2)**2-yl*v2*v3*cos(d2- 0-al))+sqr(-yl*sin(al)*(v2)**2-yl*v2*v3*sin(d2- 0-al))) =l= 2;

l32.. sqrt(sqr(yl*cos(al)*(v3)**2-yl*v3*v2*cos( 0-d2-al))+sqr(-yl*sin(al)*(v3)**2-yl*v3*v2*sin( 0-d2-al))) =l= 2;

Page 87: LP real world - cpb-us-w2.wpmucdn.com

GAMS code: simple

July 2, 2017 A. J. Conejo 87

model simpleopf /all/;solve simpleopf using nlp minimizing z;option decimals = 8;display p1.l, p2.l, q1.l, q2.l, v1.l, v2.l, v3.l, d1.l, d2.l;

Page 88: LP real world - cpb-us-w2.wpmucdn.com

GAMS code: simple

July 2, 2017 A. J. Conejo, R. Sioshansi 88

---- 46 VARIABLE p1.L = 0.03090686 VARIABLE p2.L = 0.77426500 VARIABLE q1.L = 0.32091674 VARIABLE q2.L = 0.33080185 VARIABLE v1.L = 1.09770030 VARIABLE v2.L = 1.10000000 VARIABLE v3.L = 1.06635924 VARIABLE d1.L = 0.02123196 VARIABLE d2.L = 0.04191265

Page 89: LP real world - cpb-us-w2.wpmucdn.com

This is it!

July 2, 2017 A. J. Conejo, R. Sioshansi 89