Print cvx model to external text file

Hi,

I wonder if it’s possible to print a model written in cvx to a external text file? For example, consider this model:

A = [1 2 3; 4 5 0]
b = [5; 0]
c = [10; 20; 30]

cvx_begin
variable x(3,0);
minimize c’ * x;
A * x == b;
cvx_end

Then, is posible to get this output from cvx:

output
min 10 * x1 + 20 * x2 + 30 * x3;
st:
1 * x1 + 2 * x2 + 3 * x3 == 5;
4 * x1 + 5 * x2 == 0;

Thanks,
Sebastián

No, this is not possible. The closest thing you can do is use the ‘dumpfile’ facility to create a .mat file containing the input sent to the solver and the output it returns. Type help cvx_solver_settings to see how to use this feature. You might then be able to take the input data and write your own pretty-printing routine.

MOSEK can dump problems to the LP or OPF formats which is very close to what is asked for. I am not sure if that feature can be used from CVX.

mcg, just curious as to why it’s not possible. I know solvers like Gurobi take several inputs, one being an lp file, or their API can be used directly within MATLAB as well. I’m guessing CVX uses the latter. Could it be a feature to have CVX output the same formulas it’s entering into the API into an LP file?

When I said it’s “not possible” I primarily meant it’s “not implemented.” But it is not as straightforward to produce a useful result as you might think. CVX performs quite a few transformations on your model before sending it to the solver. It will by no means be straightforward to extract your original problem variables from this model—in fact, in some cases, your variables need to come from the dual problem. If I put a lot of effort into exposing this internally generated model to the user, I guarantee that it will generate a lot of support emails asking “how do I find my variables!”

Great, thanks for the answer. I didn’t know that it uses the dual problem sometimes to formulate it.

I’m new to Mosek and I’ve been trying to do that but I can’t make it work. Do you have any suggestions?