Exporting MPS Files Using CBC APIs: Command Line, C / C++ and Python

Exporting MPS files using the CBC Command Line API

Overview: If you are using COIN from the command line you could use the export parameter to export your model to an MPS file.
Instructions: To enter the command line mode, use:

    #> ∼/Cbc-2.8.12/build/bin/cbc –

You should get the prompt “Coin:”.

After building the model interactively, issuing the following command:

    export model.mps

will export the model to an MPS file.

Exporting MPS files using the CBC C / C++ API

Instructions: Insert

    solver.writeMps(“model”,”mps”,0.0);

after you have built your model and right before the call of the optimization routine.

Note: Change the third argument 0.0 to -1.0 if you want to maximize, to 1.0 if you want to minimize or 0.0 if the solver should decide.

Example:

OsiClpSolverInterface solver;
CbcModel model(solver);
// the model is built here
solver.writeMps(“model”,”mps”,0.0);
model.branchAndBound();

Note: While you modify your model with methods from the class CbcModel, the writeMps method is a function of the OsiClpSolverInterface class.

After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.
It is automatically compressed and is now named i.e. “model.mps.gz”.

Exporting MPS files using the CBC Python API (CyLP Binding)

Instructions: Insert

    s.writeMps(“model.mps”,0,2,0)

after you have built your model and right before the call of the optimization routine.

Example:

s = CyClpSimplex()
// the model is built here
s.writeMps(“model.mps”,0,2,1.0)
s.primal()

Note: Choose 1.0 for minimization or -1.0 for maximization as fourth argument.

After saving the file and calling the python interpreter, the MPS file with the chosen name will be located in your current directory.