I recently tried to use CVX to solve MILP. But I note that CVX uses cvx_begin and cvx_end to specify the optimization problem, while the gurobi also has its own way to specify a optimization problem by using such as

model.A = [], model.obj = [], model.rhs = []. I find that this is not efficient for largel scale optimization problems, which have to specify a lot of different types of variables. Can anyone help on this? I’m a beginner of gurobi. Thank you very much.

You can access gurobi via CVX, in which case you have to follow CVX’s rules for specifying your problem. If you prefer, you can access gurobi in some other manner, in which case the CVX forum would not be the right place to get assistance.

If you wish to use CVX to access gurobi, then model.A = [], model.obj = [], model.rhs = [] , etc. are inot used. CVX transforms the input you provide it into a form gurobi can handle. It’s not clear to me from your post whether the CVX or “gurrobi” style seems more convenient to you.

Thanks for your explanation. I understand the differences now. One more question is that in Gurobi, the SOS is naturally supported by the field “model.sos().type” as you may see from the following example code for MIP in Gurobi user guide. Then how can I access this constraints for restrciting my optimziation variables in CVX?

function sos()

% Copyright 2018, Gurobi Optimization, LLC

%

% This example creates a very simple Special Ordered Set (SOS)

% model. The model consists of 3 continuous variables, no linear

% constraints, and a pair of SOS constraints of type 1.

model.ub = [1 1 2];

model.obj = [2 1 1];

model.modelsense = ‘Max’;

model.A = sparse(1,3);

model.rhs = 0;

model.sense = ‘=’;

**% Add first SOS: x1 = 0 or x2 = 0**

**model.sos(1).type = 1;**

**model.sos(1).index = [1 2];**

**model.sos(1).weight = [1 2];**

**% Add second SOS: x1 = 0 or x3 = 0**

**model.sos(2).type = 1;**

**model.sos(2).index = [1 3];**

**model.sos(2).weight = [1 2];**

% Write model to file

gurobi_write(model, ‘sos.lp’);

result = gurobi(model);

As discussed at Matlab, CVX, mosek, gurobi, Special ordered set (SOS) variables in MILP , you will have to do SOS “yourself”: in CVX. Perhaps you’d be better off just calling gurobi from its MATLAB interface, which as you say, allows you to specify SOS and let guobi take care of the details. S doe SOS purposes, Gurobi;s MATLAB interface is a higher level easier to use interface than CVX.

Great. I see now.

I used gurobi and find that it uses model.xxx to specify the problem and coefficients of all the constraints. For large scale optimziation problems, writing such coefficients in Gurobi is not an easy task. We may prefer using the “problem based” formulation as in CVX which supports matrix and vector operations, which is more self explanatory and easy to be wrote. Do you have any idea?

Thanks again.

Once you leave CVX, you’re on your own on this forum.

Regarding SOS. I recall other vendors saying that at least SOS1 is not that useful. Indeed they would normally convert them to normal linear constraints internally so they can be used to generate cutting planes etc.

Got it. Thank you very much.