To see a broader comparison of Gurobi vs. open-source solvers, please visit our open-source solvers page. To see some more information on switching to Gurobi from other commercial solvers, please visit our switching to Gurobi page.

  1. Overview
  2. CBC
  3. CPLEX
  4. GLPK
  5. LP_Solve
  6. SCIP

Exporting MPS files from open-source and commercial solvers

Exporting MPS files is easier than you may think. We are also happy to assist you both in exporting your models and, if you wish, both benchmarking your models using Gurobi and recommending specific parameter settings for Gurobi that will give you the best performance. Click on any of the above tabs to see solver-specific instructions for exporting MPS files. Once you have exported your model, simply email us at help@gurobi.com and we will enable your account for uploads so you can conveniently and confidentially send it to us for benchmarking. If you have any questions, please also feel free to contact us at help@gurobi.com.

Please note that the MPS format has not been standardized, and each solver may have its own set of conventions and extensions. If you encounter read errors or notice a discrepancy in the solution found by Gurobi, please contact us at help@gurobi.com, and we will be happy to help you figure out how to modify the file so it conforms to the official Gurobi MPS format specification.

Please refer to the following common issues we encounter and their corresponding workarounds.

CBC

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.

CPLEX

Command Line, C / C++, Python, Java and MATLAB


Exporting MPS/REW files using the CPLEX Command Line API

Instructions: After you have build your model write:

    write model.mps

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps.


Exporting MPS/REW files using the CPLEX C API

Instructions: Insert

    status = CPXwriteprob(env, lp, “model.mps”, NULL);

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

Example:

lp = CPXcreateprob(env, &status, probname); // the model is built here status = CPXwriteprob(env, lp, “model.mps”, NULL); status = CPXmipopt(env, lp);

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps. After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.


Exporting MPS/REW files using the CPLEX C++ API

Instructions: Insert

cplex.exportModel(“model.mps”);

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

Example:

IloCplex cplex(env); // the model is built here cplex.exportModel(“model.mps”); IloCplex cplex(env);

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps. After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.


Exporting MPS/REW files using the CPLEX Python API

Instructions: Insert

cpx.write(“model.mps”)

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

Example:

import cplex cpx = cplex.Cplex() // the model is built here cpx.write(“model.mps”); cpx.solve()

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps. After saving the file and calling the python interpreter, the MPS file with the chosen name will be located in your current directory.


Exporting MPS/REW files using the CPLEX JAVA API

Instructions: Insert

cplex.exportModel(“model.mps”);

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

Example:

IloCplex cplex = new IloCplex(); // the model is built here cplex.exportModel(“model.mps”); cplex.solve()

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps. After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.


Exporting MPS/REW files using the CPLEX MATLAB API

Instructions: Insert

cplex.writeModel(‘model.mps’);

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

Example:

cplex = Cplex(); // the model is built here cplex.writeModel(‘model.mps’); cplex.solve();

Note: If your MPS file is too large to be sent easily, CPLEX can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. If you want to anonymize the variable and constraint names append the file ending .rew instead of .mps. After saving the file and calling the Matlab interpreter, the MPS file with the chosen name will be located in your current directory.

LP_Solve

Command Line, C / C++, Python, Java and MATLAB Note on lp_solve: In MPS files, lp_solve may write binary variables as unbounded general integers. Thus, before writing an MPS file from lp_solve, explicitly set an upper bound of 1 for all binary variables.


Exporting MPS files using the LP_Solve Command Line API

Instructions: If you are using lp_solve through the command line you could either send us directly your lp-file or in case you use a program to output your model and pipe it into lp_solve you could use the –wmps parameter of lp_solve:

generate_model_program | lpsolve -wmps model.mps


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

Instructions: Insert

write_mps(lp, “model.mps”);

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

Example:

set_obj_fn(lp, row) write_mps(lp, “model.mps”); solve(lp);

After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.


Exporting MPS files using the LP_Solve Python API

Instructions: Insert

lpsolve(‘write_mps’, lp, ‘model.mps’)

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

Example:

lpsolve(‘add_constraint’, lp, [12.68, 0, 0.08, 0.9], GE, 4) lpsolve(‘write_mps’, lp, ‘model.mps’) lpsolve(‘solve’, lp)

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


Exporting MPS files using the LP_Solve JAVA API

Instructions: Insert

problem.writeMps(“model.mps”);

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

Example:

problem.strAddConstraint(“1 2 1 4”, LpSolve.EQ, 8); problem.writeMps(“model.mps”); problem.solve();

After saving the file, compiling your code and executing it, the MPS file with the chosen name will be located in your current directory.


Exporting MPS files using the LP_Solve MATLB API

Instructions: Insert

mxlpsolve(‘write_mps’, lp, ‘model.mps’);

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

Example:

mxlpsolve(‘add_constraint’, lp, [12.68, 0, 0.08, 0.9], 2, 4); mxlpsolve(‘write_mps’, lp, ‘model.mps’); mxlpsolve(‘solve’, lp)

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

GLPK

Command Line and C / C++


Exporting MPS files using the GLPK Command Line API

Overview: Creating MPS file from a GNU MathProg file (*.mod file) with the command line tool of GLPK (glpsol)
Instructions: Open the command line and change to the directory, where the *.mod file is located. Execute the following command (you need to replace problem.mod with the name of your file)

glpsol –model “problem.mod” –wmps “model.mps”

Replacing “model.mps” with “model.mps.gz” will again result in a compressed file. After the execution of the command the (compressed) MPS file with the chosen name is located in your current directory.


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

Instructions: Insert

glp_write_mps(lp, GLP_MPS_DECK, NULL, “model.mps”);

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

Example:

glp_load_matrix(lp, 9, ia, ja, ar); glp_write_mps(lp, GLP_MPS_DECK, NULL, “model.mps”); glp_simplex(lp, NULL);

Note: If your MPS file is too large to be sent easily, glpk can compress it directly if you append .gz after the filename, i.e. “model.mps.gz”. After saving the file, compiling your code and executing it, the (compressed) MPS file with the chosen name will be located in your current directory.

SCIP

Command Line and C


Exporting MPS files using the SCIP Command Line API

Instructions: After you have built your model write:

write problem model.mps

To anonymize a model, use the following code instead:

write genproblem model.mps


Exporting MPS files using the SCIP C API

Instructions: Insert:

SCIPwriteOrigProblem(scip, “model.mps”, NULL, 0);

after you have built your model and right before the call of the optimization routine. If you want to anonymize the variable and constraint names, pass a “1” as last parameter to SCIPwriteOrigProblem() instead.

Guidance for Your Journey

30 Day Free Trial for Commercial Users

Start solving your most complex challenges, with the world's fastest, most feature-rich solver.

Always Free for Academics

We make it easy for students, faculty, and researchers to work with mathematical optimization.

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization