Skip to content

Instantly share code, notes, and snippets.

@johanlofberg
Created May 18, 2021 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanlofberg/03277cf8b75a8124f4b2ff82dd60fbf2 to your computer and use it in GitHub Desktop.
Save johanlofberg/03277cf8b75a8124f4b2ff82dd60fbf2 to your computer and use it in GitHub Desktop.
%% Nonconvex quadratic constraint
x1 = sdpvar(1,1);
x2 = sdpvar(1,1);
x3 = sdpvar(1,1);
p = -2*x1+x2-x3;
F = [x1*(4*x1-4*x2+4*x3-20)+x2*(2*x2-2*x3+9)+x3*(2*x3-13)+24>=0,
4-(x1+x2+x3)>=0,
6-(3*x2+x3)>=0,
x1>=0,
2-x1>=0,
x2>=0,
x3>=0,
3-x3>=0]
options = sdpsettings('solver','bmibnb');
optimize(F,p,options);
%% Nonconvex QP
x1 = sdpvar(1,1);
x2 = sdpvar(1,1);
x3 = sdpvar(1,1);
x4 = sdpvar(1,1);
x5 = sdpvar(1,1);
x6 = sdpvar(1,1);
p = -25*(x1-2)^2-(x2-2)^2-(x3-1)^2-(x4-4)^2-(x5-1)^2-(x6-4)^2;
F = [(x3-3)^2+x4>=4,(x5-3)^2+x6>=4,x1-3*x2<=2, -x1+x2<=2,
x1-3*x2<=2, x1+x2>=2,6>=x1+x2>=2,1<=x3<=5, 0<=x4<=6, 1<=x5<=5, 0<=x6<=10, x1>=0,x2>=0];
options = sdpsettings('solver','bmibnb');
optimize(F,p,options);
%% Tighter tolerances
options = sdpsettings('solver','bmibnb','bmibnb.relgaptol',1e-4);
optimize(F,p,options);
%% Nonconvex polynomial programming
sdpvar x y
F = [x^3+y^5 <= 5, y >= 0];
options = sdpsettings('verbose',1,'solver','bmibnb');
optimize(F,-x,options)
%% General nonlinearities
p = sin(1+y*x)^2+cos(y*x);
optimize([-1 <= [x y] <= 1],p,sdpsettings('solver','bmibnb'));
%% Nonconvex semidefinite programming
x = sdpvar(1,1);
y = sdpvar(1,1);
t = sdpvar(1,1);
A0 = [-10 -0.5 -2;-0.5 4.5 0;-2 0 0];
A1 = [9 0.5 0;0.5 0 -3 ; 0 -3 -1];
A2 = [-1.8 -0.1 -0.4;-0.1 1.2 -1;-0.4 -1 0];
K12 = [0 0 2;0 -5.5 3;2 3 0];
F = [x>=-0.5, x<=2, y>=-3, y<=7];
F = [F, A0+x*A1+y*A2+x*y*K12-t*eye(3)<=0];
options = sdpsettings('solver','bmibnb');
optimize(F,t,options);
%% Nonconvex semidefinite programming
A = [-1 2;-3 -4];B = [1;1];
P = sdpvar(2,2);
K = sdpvar(1,2);
F = [P>=0, (A+B*K)'*P+P*(A+B*K) <= -eye(2)-K'*K];
F = [F, -0.1 <= K <= 0.1];
options = sdpsettings('solver','bmibnb');
optimize(F,trace(P),options);
%% Nonconvex semidefinite programming
F = [P>=0, [-eye(2) - ((A+B*K)'*P+P*(A+B*K)) K';K 1] >= 0];
F = [F, K<=0.1, K>=-0.1];
options = sdpsettings('solver','bmibnb');
optimize(F,trace(P),options);
%% Nonconvex semidefinite programming
F = [P>=eye(2), A'*P+P*A <= -2*t*P];
F = [F, t >= 0];
options = sdpsettings('solver','bmibnb');
optimize(F,-t,options);
%% Alternative
F = [P >= 0, trace(P) == 1, A'*P+P*A <= -2*t*P];
F = [F, t >= 0];
optimize(F,-t,options);
%% Alternative
F = [P>=0, trace(P)==1, A'*P+P*A <= -2*t*P];
F = [F, t >= 0];
F = [F, trace(A'*P+P*A)<=-2*t]
optimize(F,-t,options);
%% Alternative
F = [P>=0,A'*P+P*A <= -2*t*P, t >= 0];
F = [F, trace(P)==1];
F = [F, trace(A'*P+P*A)<=-2*t];
F = [F, [-A'*P-P*A P*t;P*t P*t/2] >= 0];
optimize(F,-t,options);
%% Alternative
F = [P >=0 ,A'*P+P*A <= -2*t*P, t >= 0];
F = [F, trace(P) == 1];
F = [F, trace(A'*P+P*A) <= -2*t];
F = [F, cut([-A'*P-P*A P*t;P*t P*t/2] >= 0)];
optimize(F,-t,options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment