Download presentation
Published byRussell Hubbard Modified over 9 years ago
1
Hossein Sahebdel Iran University Of Science And Technology May 12
YALMIP Toolbox Hossein Sahebdel Iran University Of Science And Technology May 12
2
Intruduction Installation 1
YALMIP 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
3
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
4
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
5
Linear programming 4
6
Quadratic programming
5
7
Second Order Cone programming
6
8
Semidefinite programming
7
9
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
10
Solvers 9 Linear programming (free)
CDD, CLP, GLPK, LPSOLVE, QSOPT, SCIP Linear programming (commercial) CPLEX ,GUROBI ,LINPROG, MOSEK ,XPRESS Quadratic programming (free) BPMPD, CLP, OOQP, QPC, qpOASES, quadprogBB (nonconvex QP) Quadratic programming (commercial) CPLEX, GUROBI ,MOSEK ,NAG, QUADPROG, XPRESS 9
11
Solvers 10 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 10
12
Variable declaration Sdpvar
sdpvar is used to define YALMIPs symbolic decision variables. x = sdpvar(n) x = sdpvar(n,m) x = sdpvar(n,m,'type') x = sdpvar(n,m,'type','field') x=sdpvar(dim1,dim2,dim3,...,dimn,'type','field') sdpvar x 11
13
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
14
Constraints F = alldifferent(X) Examples The following example finds an integer vector with all numbers between 1 and 5. x = intvar(5,1); F = [alldifferent(x), 1<=x<=5]; optimize(F); value(x) Ans=[ ]’ 13 4
15
Constraints F = binary(x) Setting up a binary linear program {min cTx subject to Ax≤b} can be done as x = binvar(n,1); optimize(A*x<b,c'*x) or x = sdpvar(n,1); optimize([A*x<=b, binary(x)],c'*x) 14 4
16
Constraints alldifferent binary check checkset cone cut dilate dual dualize hull imagemodel integer is ismember primalize rank rcone robustify set sos sosd 15 4
17
options options = sdpsettings('field',value,'field',value,...) 16 4
18
Optimize optimize is the common function for solving optimization problems (replaces solvesdp) diagnostics = optimize(Constraints,Objective,options) 17 4
19
Linear programming 4 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]; 18 4
20
Quadratic programming
x = [ ]'; 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); 19 4
21
Quadratic programming
F = [-bound <= residuals <= bound]; optimize(F,sum(bound)); x_L1 = value(x_hat); optimize([],residuals'*residuals); x_L2 = value(x_hat); bound = sdpvar(1,1); 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') 20 4
22
STANDARD MPC % Model data A = [2 -1;1 0.2]; B = [1;0]; nx = 2; % Number of states nu = 1; % Number of inputs % MPC data Q = eye(2); R = 2; N = 7; % Initial state x0 = [3;1]; u = sdpvar(repmat(nu,1,N)); 21 4
23
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) end plot(1:7,xx(1,1:7),1:7,xx(2,1:7)) 22 4
24
Bilevel Programming 23 4
25
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); 24 4
26
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))]; end KKT = [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) 25 4
27
Bilevel Programming x =[ ]’ z =[ ]’ lambda =[ ]’ slack = [ ]’ 26 4
28
Residential Energy Hub
27
29
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=[ ]; 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
30
F = [F, 25>T(2,s)>15 , T(2,1)==18]; F = [F, T(2,i+1)==T(2,i)-0
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 PP(j,:)=PP(j,:).*cost; F = [F,Ptotal==sum(PP), abs(Ptotal(1,i))<2000] obj = sum(PP); optimize(F,obj); 29
31
30
32
31
33
32
34
33
35
34
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.