Export Yalmip Model to Cplex Format

79 views
Skip to first unread message

Lun Yang

unread,
Oct 18, 2018, 4:21:29 PM10/18/18
to YALMIP
Dear professor Löfberg,

I was trying to export Yalmip model to Cplex format. After exporting, I tried to run the model directly in Cplex, but I got a different solution. Please see the code below,

n = 5;
S = randn(n);S = S*S'/1000; 
mu  = rand(1,n)/100;             
w = sdpvar(n,1);
F = [sum(w)==1, 1>=w>=0, w'*S*w<=sum(sum(S))/n^2];
Obj = -mu*w;
options = sdpsettings('solver','cplex');
optimize(F,Obj,options);
value(w)

% Export the model to Cplex, and rerun in Cplex
[model,~,~,~] = export(F,Obj,options);
cmodel = Cplex(model);
sol = cmodel.solve();
sol.x

Is this the correct way to export Yalmip model to Cplex? I am using Matlab 2018a, Cplex 12.8 and Yalmip '20180612'.

Thank you very much.

Best,
Lun Yang

Johan Löfberg

unread,
Oct 19, 2018, 1:50:05 AM10/19/18
to YALMIP
The call would be

 [x,fval,exitflag,output] = cplexqcp(model.H, model.f, model.Aineq,model.bineq,model.Aeq,model.beq,model.Li,model.Qi,model.ri,model.lb,model.ub,model.x0,model.options);


and the variables of interest are x(1:length(w)) (YALMIP introduces extra variables to normalize the SOCP cones)

Lun Yang

unread,
Oct 19, 2018, 11:24:19 AM10/19/18
to YALMIP
Thank you professor Löfberg. 

In order to get the same results, is there a way to see which Cplex Matlab function Yalmip calls? The reason I am asking is, later when my model is getting complicated, cplexqcp might not be the correct solver function Yalmip calls?

Thank you again,

Best,
Lun Yang

Johan Löfberg

unread,
Oct 19, 2018, 11:40:12 AM10/19/18
to YALMIP
which function is called depends on the model of course. You would have to study call_cplexibm_qcmiqp and  call_cplexibm_miqp.m

Lun Yang

unread,
Oct 19, 2018, 11:41:20 AM10/19/18
to YALMIP
thank you, exactly what I need.

Lun

Lun Yang

unread,
Oct 19, 2018, 12:01:27 PM10/19/18
to YALMIP
I quick follow up question. Is there a way to get the solution pool from directly calling the following

[x,fval,exitflag,output] = cplexqcp(model.H, model.f, model.Aineq,model.bineq,model.Aeq,model.beq,model.Li,model.Qi,model.ri,model.lb,model.ub,model.x0,model.options);

Maybe this is more a Cplex question than Yalmip. It will be great if you know the answer.

thanks,
Lun

Johan Löfberg

unread,
Oct 19, 2018, 12:31:18 PM10/19/18
to YALMIP
as you say, that's a cplex question
Reply all
Reply to author
Forward
0 new messages