How to use CPLEX to solve a SOCP

318 views
Skip to first unread message

Clark St

unread,
Sep 25, 2013, 11:18:09 PM9/25/13
to yal...@googlegroups.com
I had a SOCP, and it's very big. I used sedumi to solve this program, but it takes a lot of time, so I want to try the CPLEX solver.
But I don't known how to set it,  I give the sdpsettings('solver','cplex'), but the answer is zeros, do I need set some other settings?
Thanks.

Johan Löfberg

unread,
Sep 26, 2013, 2:25:28 AM9/26/13
to yal...@googlegroups.com
What do you mean with "the answer is zero". Do you mean that the diagnostic flag in the struct returned from solvesdp is zero, or are all optimal values zero? What is the diagnostic flag? What is displayed?

Clark St

unread,
Sep 26, 2013, 6:19:12 AM9/26/13
to yal...@googlegroups.com
It shows "Successfully solved (CPLEX-IBM)", but the the optimal values are all zeros.
I write it like this:
options=sdpsettings('solver','cplex');
sol=solvesdp(F,objective,options);

if I change the solver to sedumi, it works well.
Did I set something wrong or missing?

Johan Löfberg

unread,
Sep 26, 2013, 8:53:02 AM9/26/13
to yal...@googlegroups.com
And all zeros is not feasible? If cplex solves the problem without any complaints, then most likely 0 is a feasible solution. If you claim this cannot be, you would have to show us your code

Clark St

unread,
Sep 26, 2013, 9:08:44 PM9/26/13
to yal...@googlegroups.com
This is the code:

function [model] = M4(trainA,trainB,C)
%M4 Summary of this function goes here
%   Detailed explanation goes here
[nx,col]=size(trainA);
ny=size(trainB,1);
sigmaA=cov(trainA);
sigmaB=cov(trainB);
if (nx+ny)>5000
    muA=mean(trainA,1);
    muB=mean(trainB,1);
    dA=pdist2(trainA,muA,'mahalanobis',sigmaA);
    dB=pdist2(trainB,muB,'mahalanobis',sigmaB);
    [~,ix]=sort(-dA);
    nx=2*floor(nx/10);
    trainA=trainA(ix(1:nx),:);
    [~,ix]=sort(-dB);
    ny=2*floor(ny/10);
    trainB=trainB(ix(1:ny),:);
end
rho=sdpvar(1);
w=sdpvar(col,1);
b=sdpvar(1);
xiA=sdpvar(nx,1);
xiB=sdpvar(ny,1);
xi=[xiA;xiB];
F=[];
F=[F,rho*sqrt(w'*sigmaA*w)-xiA-trainA*w-b<=0];
F=[F,rho*sqrt(w'*sigmaB*w)-xiB+trainB*w+b<=0];
F=[F,0<=xi];
F=[F,1<=rho<=50,uncertain(rho)];
objective=C*sum(xi)-rho;
options=sdpsettings('solver','cplex'); %sedumi could work
sol=solvesdp(F,objective,options);
w=double(w);
b=double(b);
model.w=w;
model.bisa=b;
model.sigmaA=sigmaA;
model.sigmaB=sigmaB;

end

Thank you for your help.

Johan Löfberg

unread,
Sep 27, 2013, 2:18:45 AM9/27/13
to yal...@googlegroups.com
Clearly 0 is a feasible solution (and optimal). Since xi is non-negative, the best possible ever possible would be xi = 0, which is feasible if you set w and b to zero.

BTW, the uncertainty in the objective is pretty redundant. I hope you realize it makes absolutely no difference. If not, your model does probably not describe what you intend it to describe.

Clark St

unread,
Sep 27, 2013, 2:31:18 AM9/27/13
to yal...@googlegroups.com

The problem is like this, did I write some thing wrong with the model?

But why the sedumi can give a non-zeros solution


Johan Löfberg

unread,
Sep 27, 2013, 2:38:57 AM9/27/13
to yal...@googlegroups.com
First, I don't understand why treat rho as an uncertain variable, and the look for the worst-case separation.

Anyway. My guess is that your data is separable, hence xi=0 feasible. With that, b=w=0 is feasible, since you have no strict term anywhere. Typically in separation models, you have a constant to get the nominal separation, i.e., w^Tx+b >=1 for some samples and w'*x <= -1 for others, and then you add fancy stuff to deal with non-separability (your slacks, and the norm you have which I guess comes from a probabilistic separation)

The fact that sedumi returns something else is due to the non-uniqueness of the solution. SeDuMi returns xi=0 though I hope. w and b is not unique if separable, and even worse since you have no strict condition, 0 is feasible

Johan Löfberg

unread,
Sep 27, 2013, 2:40:44 AM9/27/13
to yal...@googlegroups.com
Note that the model says w not equal to 0, which is an impossible constraint, hence some hack has to be introduced, such as adding a strict separation constraint.

Clark St

unread,
Sep 27, 2013, 2:53:28 AM9/27/13
to yal...@googlegroups.com
Sorry, I just don't known how to use yalmip, and if I not treat rho as an uncertain var, it will give me Nan.
Can you give me some links of these problems to learn how to wirte the model?

Johan Löfberg

unread,
Sep 27, 2013, 2:59:21 AM9/27/13
to yal...@googlegroups.com
It is not your YALMIP code which is wrong, but your problem is badly posed if zero is feasible

The problem is not directly convex in rho and w, so you have to come up with a convex model, or solve the problem for various fixed rho, and pick the best solution (unless they say in the paper you are working with how to reformulate this to a standard convex problem)



Clark St

unread,
Sep 27, 2013, 3:04:34 AM9/27/13
to yal...@googlegroups.com
Thank you for your answer, I will find how to fix it.
Reply all
Reply to author
Forward
0 new messages