+ All Categories
Home > Documents > YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Date post: 01-Jan-2016
Category:
Upload: russell-hubbard
View: 231 times
Download: 11 times
Share this document with a friend
35
YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12
Transcript
Page 1: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

YALMIP Toolbox

Hossein SahebdelIran University Of Science And

TechnologyMay 12

Page 2: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Intruduction InstallationYALMIP is entirely based on m-code, and is thus easy to install. Remove any old version of YALMIP, unzip the file YALMIP.zip and add the following directories to your MATLAB path /yalmip /yalmip/extras /yalmip/demos /yalmip/solvers /yalmip/modules /yalmip/modules/parametric /yalmip/modules/moment /yalmip/modules/global /yalmip/modules/sos /yalmip/operators

1

Page 3: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

What is YALMIP• YALMIP is a modelling language for advanced

modeling and solution of convex and nonconvex optimization problems. It is implemented as a free (as in no charge) toolbox for MATLAB. • The main motivation for using YALMIP is rapid

algorithm development. The language is consistent with standard MATLAB syntax, thus making it extremely simple to use for anyone familiar with MATLAB.

2

Page 4: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Problem classes

• The modelling language supports a large number of optimization classes, such as linear, quadratic, second order cone, semidefinite, mixed integer conic, geometric, local and global polynomial, multiparametric, bilevel and robust programming.

3

Page 5: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Linear programming

4

Page 6: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Quadratic programming

5

Page 7: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Second Order Cone programming

6

Page 8: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Semidefinite programming

7

Page 9: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Solvers

• One of the central ideas in YALMIP is to concentrate on the language and the higher level algorithms, while relying on external solvers for the actual computations. However, YALMIP also implements internal algorithms for global optimization, mixed integer programming, multiparametric programming, sum-of-squares programming and robust optimization. These algorithms are typically based on the low-level scripting language available in YALMIP.

8

Page 11: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Solvers

• Second-order cone programming (free)• ECOS, SDPT3, SEDUMI • Second-order cone programming (commercial)• CPLEX ,GUROBI ,MOSEK • Semidefinite programming (free)• CSDP, DSDP, LOGDETPPA, PENLAB, SDPA, SDPLR, SDPT3, SDPNAL,

SEDUMI • Semidefinite programming (commercial)• LMILAB, MOSEK ,PENBMI, PENSDP• General nonlinear programming and other solvers• BARON, FILTERSD, FMINCON, GPPOSY, IPOPT, KNITRO, KYPD,

LMIRANK, MPT, NOMAD, PENLAB, SNOPT, STRUL, VSDP, SparsePOP 1

0

Page 13: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Variable declaration

• semivar defines a semi-continuous variable •uncertain is used to declare variables as

uncertain. •binvar is used to define decision variables

constrained to be binary (0 or 1). •blkvar is used to simplify definition of block-

structured variables. • intvar used to define decision variables with

integer elements. 12

Page 16: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Constraints

alldifferent binary check checkset cone cut dilate dual dualize hull imagemodel integer is ismember primalize rank rcone robustify set sos sosd

415

Page 18: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Optimize

optimize is the common function for solving optimization problems (replaces solvesdp)

diagnostics = optimize(Constraints,Objective,options)

417

Page 19: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Linear programming

•a = sdpvar(2,1);•b = sdpvar(1);•u = sdpvar(1,25);•v = sdpvar(1,25);

•Constraints = [a'*greens+b >= 1-u, a'*blues+b <= -(1-v), u>=0, v>=0,-1<=a<=1];

•optimize(Constraints,sum(u)+sum(v))•x = sdpvar(2,1);

•P1 = [-5<=x<=5, value(a)'*x+value(b)>=0];•P2 = [-5<=x<=5, value(a)'*x+value(b)<=0];

418

Page 20: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Quadratic programmingx = [1 2 3 4 5 6];'t = (0:0.02:2*pi);'

a = [sin(t) sin(2*t) sin(3*t) sin(4*t) sin(5*t) sin(6*t)];e = (-4+8*rand(length(a),1));e(100:115) = 30;y = a*x+e;plot(t,y);x_hat = sdpvar(6,1);residuals = y-a*x_hat;bound = sdpvar(length(residuals),1);

419

Page 21: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Quadratic programmingF = [-bound <= residuals <= bound] ;

optimize(F,sum(bound));x_L1 = value(x_hat);optimize([],residuals'*residuals);x_L2 = value(x_hat);bound = sdpvar(1,1);F = [-bound <= residuals <= bound];optimize(F,bound);x_Linf = value(x_hat);plot(t,[y a*x_L1 a*x_L2 a*x_Linf]) ;

legend('y','a*x_L1','a*x_L2','a*x_Linf')420

Page 22: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

STANDARD MPC% Model dataA = [2 -1;1 0.2];B = [1;0];nx = 2; % Number of statesnu = 1; % Number of inputs% MPC dataQ = eye(2);R = 2;N = 7;% Initial statex0 = [3;1];u = sdpvar(repmat(nu,1,N)); 421

Page 23: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

constraints = [];objective = 0;x = x0;ff=zeros(1,7)xx=zeros(2,7)for k = 1:N x = A*x + B*u{k} objective = objective + norm(Q*x,1) + norm(R*u{k},1); constraints = [constraints, -5 <= u{k}<= 1, -5<=x<=5]; optimize(constraints,objective); ff(k)=value(u{1}) xx(:,k)=value(x)endplot(1:7,xx(1,1:7),1:7,xx(2,1:7))

422

Page 24: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Bilevel Programming

423

Page 25: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Bilevel Programming

• n = 3;m = 2;

Q = randn(n,n);Q = Q*Q';c = randn(n,1);d = randn(m,1);A = randn(15,n);b = rand(15,1)*2*n;E = randn(15,m);

H = randn(m,m);H = H*H';e = randn(m,1);f = randn(n,1);F = randn(5,m);h = rand(5,1)*2*m;G = randn(5,n);

424

Page 26: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Bilevel Programming

x = sdpvar(n,1);z = sdpvar(m,1);lambda = sdpvar(length(h),1);slack = h + G*x - F*z;

KKT = [H*z + e + F'*lambda == 0, F*z <= h + G*x, lambda >= 0];

for i = 1:length(h) KKT = [KKT, ((lambda(i)==0) | (slack(i) == 0))];endKKT = [KKT, lambda <= 100, -100 <= [x;z] <= 100];optimize([KKT, A*x <= b + E*z], 0.5*x'*Q*x + c'*x + d'*z);value(x)value(z)value(lambda)value(slack)

425

Page 27: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Bilevel Programming

x =[ -23.8442 10.2818 -28.7450]’z =[ 1.6421 -26.1612]’lambda =[50.0000 29.0047 50.0000 50.0000 50.0000]’slack = [ 29.1818 91.8190 1.8254 26.7669 29.9262]’

426

Page 28: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

Residential Energy Hub

27

Page 29: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

P = binvar(5,48);

T = sdpvar(3,48);

cost=zeros(1,48);

cost(1,1:12)=1; cost(1,13:24)=2; cost(1,25:36)=4; cost(1,36:48)=2;

power(1,1:48)=450; power(2,1:48)=500; power(3,1:48)=600; power(4,1:48)=400 power(5,1:48)=500;

Ptotal=sdpvar(1,48);

Tout=[23 23 22 21 20 20 19 21 19 21 20 21 21 21 20 22 24 26 26 28 ...

28 28 28 28 30 31 30 27 29 29 30 29 29 30 28 28 27 26 25 25 25 25 25 25 25 25 23 23];

i=1:47;

s=1:48;

F = [8>T(1,s)>3];

F = [F, T(1,i+1)==T(1,i)-0.002*450*P(1,i)+0.03*Tout(1,i)]; 28

Page 30: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

F = [F, 25>T(2,s)>15 , T(2,1)==18];

F = [F, T(2,i+1)==T(2,i)-0.02*500*P(2,i)+0.12*Tout(1,i)];

F = [F, 80>T(3,s)>70];

F = [F, T(3,i+1)==T(3,i)+0.002*600*P(3,i)-0.035*Tout(1,i)];

F = [F, P(4,1:12)==0, P(4,25:48)==0, sum(P(4,:))==10];

F = [F, P(5,1:25)==0, sum(P(5,:))==15];

PP=sdpvar(6,48);

for j=1:5

PP(j,:)=P(j,:).*power(j,:);

end

for j=1:5

PP(j,:)=PP(j,:).*cost;

end

F = [F,Ptotal==sum(PP), abs(Ptotal(1,i))<2000]

obj = sum(PP);

optimize(F,obj); 29

Page 31: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

30

Page 32: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

31

Page 33: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

32

Page 34: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

33

Page 35: YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12.

34


Recommended