Can you save a CP-SAT model as an MPS file?

972 views
Skip to first unread message

Raphael C

unread,
May 13, 2022, 11:05:25 AM5/13/22
to or-tools-discuss
I have a CP-SAT model I make in Python using 

from ortools.sat.python import cp_model
model = cp_model.CpModel()
for i in range(1000):
        cpVars += [model.NewBoolVar('v%d' % i)]
[...]
model.Maximize(sum(cpVars))


I would like to also run this with gurobi but that isn't working with the current version of ortools.  Is it possible to export the model to an MPS file instead?



Laurent Perron

unread,
May 13, 2022, 11:23:30 AM5/13/22
to or-tools-discuss
No. CP-SAT supports much more complex constraints than linear constraints.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/9847e9be-46b1-41ca-8fb6-0016d2add9dbn%40googlegroups.com.

Laurent Perron

unread,
May 13, 2022, 11:35:15 AM5/13/22
to or-tools-discuss
Actually, In some really limited cases (if you have only non-reified linear constraint and simple Boolean constraint), using the flag --cp_model_dump_models, we will dump a version of the model in the MpModelProto format that you can later convert to mps.

to enable it, you need to set the cp_model_dump_models C++ flag. See https://github.com/google/or-tools/blob/49b6301e1e1e231d654d79b6032e79809868a70e/examples/tests/pywrapinit_test.py#L26 on how to bridge the python code with the C++ flags.

Once this is done, it will write in /tmp/ a MpModelProto. You can load this in linear solver, and then export to MPS.

As you can imagine, this is only used to debug currently.

--Laurent


Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Stuart Rogers

unread,
Aug 19, 2022, 12:57:01 PM8/19/22
to or-tools-discuss
Actually, In some really limited cases (if you have only non-reified linear constraint and simple Boolean constraint)
Do these cases include mixed integer linear programs such as a simple facility location problem like the p-median problem?

Laurent Perron

unread,
Aug 19, 2022, 1:04:32 PM8/19/22
to or-tools-discuss
It does not care about the type of problems, just the type of constraints. 

Reply all
Reply to author
Forward
0 new messages