This user guide for the Optimization Solver describes how to call the solver, input problems, and provides a list of solver APIs.
This software has many APIs and new features are added frequently. For detailed API descriptions, you will often be directed to the MindOpt User Guide - Full Version. We apologize for any inconvenience this may cause. You can switch the document language and version on the page.
How to call the Optimization Solver
Before you start, download and install the solver software development kit (SDK) and obtain the necessary permissions. For more information, see Quick Start (Activation and Usage) and Download and install the solver SDK.
The following sections provide simple examples. For detailed instructions on how to call the solver and for complete examples, see More.
Command line call example
On Linux and macOS, assume that you have installed MindOpt to the directory specified by the `$MINDOPT_HOME` environment variable as described in the installation document:
mindopt $MINDOPT_HOME/examples/data/afiro.mpsOn Windows:
mindopt %MINDOPT_HOME%\examples\data\afiro.mpsC/C++/C#/Java/Python/MATLAB call example
The APIs for V1.x and later are mostly different from the APIs for V0.x. Ensure that you are using the correct version.
V1.x
env = mindoptpy.Env()
env.start()
model = mindoptpy.read(filename, env)
model.optimize()
print(f"Optimal objective value is: {model.objval}")
for v in x:
print(f"{v.VarName} = {v.X}")MDOEnv env = new MDOEnv();
MDOModel model = new MDOModel(env, filename);
model.optimize();
System.out.println("Optimal objective value is: " + model.get(MDO.DoubleAttr.ObjVal));
MDOVar[] x = model.getVars();
for (int i = 0; i < x.length; ++i) {
System.out.println(x[i].get(MDO.StringAttr.VarName) + " = " + x[i].get(MDO.DoubleAttr.X));
}MDOEnv env = MDOEnv();
MDOModel model = MDOModel(env, filename);
model.optimize();
std::cout << "Optimal objective value is: " << model.get(MDO_DoubleAttr_ObjVal) << std::endl;
std::vector<MDOVar> vars = model.getVars();
for (auto v : vars) {
std::cout << v.get(MDO_StringAttr_VarName) << " = " << v.get(MDO_DoubleAttr_X) << std::endl;
}MDOenv* env;
MDOemptyenv(&env);
MDOstartenv(env);
MDOmodel* model;
double obj;
MDOreadmodel(env, argv[1], filename);
MDOoptimize(model);
MDOgetdblattr(model, MDO_DBL_ATTR_OBJ_VAL, &obj);
printf("Optimal objective value is: %f\n", obj);
/* Free the environment. */
MDOfreemodel(model);
MDOfreeenv(env);MDOEnv env = new MDOEnv();
MDOModel model =new MDOModel(env, filename);
model.optimize();
Console.WriteLine($"Optimal objective value is: {model.Get(MDO.DoubleAttr.ObjVal)}");
MDOVar[] vars = model.GetVars();
for (int i = 0; i < vars.Length; i++)
{
Console.WriteLine($"{vars[i].Get(MDO.StringAttr.VarName)} = {vars[i].Get(MDO.DoubleAttr.X)}");
}model = mindopt_read(file);
result = mindopt(model);
for v=1:length(result.X)
fprintf('%s %d\n', model.varnames{v}, result.X(v));
end
fprintf('Optimal objective value is: %e\n', result.ObjVal);
objval = result.ObjVal;For complete code examples, see More.
V0.x
# Method 1: A new model creation method was introduced in version 0.19.0. This method provides faster cloud authentication and consumes less concurrency.
env = mindoptpy.MdoEnv()
model = mindoptpy.MdoModel(env)
model.read_prob(filename)
model.solve_prob()
model.display_results()
# Method 2: The old model creation method is still supported.
# model = mindoptpy.MdoModel()
# model.read_prob(filename)
# model.solve_prob()
# model.display_results()//<dependency>
// <groupId>com.alibaba.damo</groupId>
// <artifactId>mindoptj</artifactId>
// <version>[0.20.0,)</version>
//</dependency>
// Load the dynamic-link library, as follows:
Mdo.load("c:\\mindopt\\0.20.0\\win64_x86\\lib\\mindopt_0_20_0.dll");
// Method 1: A new model creation method was introduced in version 0.19.0. This method provides faster cloud authentication and consumes less concurrency.
// Set up the environment during program initialization, for example, in the setup phase of MapReduce.
MdoEnv env = new MdoEnv();
// Create a model.
MdoModel model = env.createModel();
model.readProb(filename)
model.solveProb();
model.displayResult();
model.free();
// The Java SDK requires you to manually release the env at the end of the program, for example, in the cleanup phase of MapReduce.
env.free();
// Method 2: The old model creation method is still supported but is marked as deprecated and will be removed in a future version.
/*
MdoModel model = new MdoModel();
model.readProb(filename)
model.solveProb();
model.displayResult();
*/// Method 1: A new model creation method was introduced in version 0.19.0. This method provides faster cloud authentication and consumes less concurrency.
using mindopt::MdoEnv;
MdoEnv env;
MdoModel model(env);
model.readProb(filename);
model.solveProb();
model.displayResults();
// Method 2: The old model creation method is still supported.
/*
MdoModel model;
model.readProb(filename);
model.solveProb();
model.displayResults();
*/// Method 1: A new model creation method was introduced in version 0.19.0. This method provides faster cloud authentication and consumes less concurrency.
MdoEnvPtr env;
MdoMdlPtr model;
Mdo_createEnv(&env);
Mdo_createMdlWithEnv(&model, env);
Mdo_readProb(model, filename);
Mdo_solveProb(model);
Mdo_displayResults(model);
Mdo_freeMdl(&model);
// The C SDK requires you to manually release the env.
Mdo_freeEnv(&env);
// Method 2: The old model creation method is still supported.
/*
MdoMdlPtr model;
Mdo_createMdl(&model);
Mdo_readProb(model, filename);
Mdo_solveProb(model);
Mdo_displayResults(model);
Mdo_freeMdl(&model);
*/For complete code examples, see the V0.x documentation.
Supported optimization problems
The current version of the solver supports the following:
Linear programming: The solver provides comprehensive capabilities for solving linear programming (LP) problems. It supports the primal/dual simplex method and the interior-point method. It also supports solving large-scale network flow optimization problems.
Integer programming: The solver supports the branch-and-cut method for mixed-integer linear programming (MILP) problems.
Nonlinear programming: The solver supports convex quadratic programming (QP) problems and semidefinite programming (SDP) problems.
Input methods for optimization problems
You can input optimization problems in three ways: by file, using the data modeling API, or by calling external modeling tools.
Method 1: File input
The solver supports the MPS format and the LP format, such as
.mpsand.lpfiles, and their compressed versions, such as.mps.gzand.mps.bz2.The solver supports the
.dat-sformat, which is used in SDP problem examples.The solver supports the
.qpsformat, which is used for QP problem data.The `mindoptampl` module supports
.nlfile input. For example, you can run themindoptampl filename.nlcommand.
For more information, see More.
Method 2: Modeling API input
The APIs for V1.x and later are mostly different from the APIs for V0.x. Ensure that you are using the correct version.
V1.x
Multiple related APIs are available that support row-wise data input.
The following is a brief Python example:
Use
mindoptpy.Model.modelsense = MDO.MINIMIZEto set the objective function to minimization.Use
mindoptpy.Model.addVar()to add optimization variables and define their lower bounds, upper bounds, objective coefficients, names, and types.Use
mindoptpy.Model.addConstrs()to add constraints.
For more information, see More. For a list of attributes, see More. The API chapters also contain complete examples for each language.
V0.x
Multiple related APIs are available, and the same data can be input in various ways.
The following is a brief Python example for row-wise input:
Use
mindoptpy.MdoModel.set_int_attr()to set the objective function to minimization.Use
mindoptpy.MdoModel.add_var()to add four optimization variables and define their lower bounds, upper bounds, names, and types.Use
mindoptpy.MdoModel.add_cons()to add constraints.
The following is a brief Python example for column-wise input:
Use
mindoptpy.MdoModel.set_int_attr()to set the objective function to minimization.First, call
mindoptpy.MdoModel.add_cons()to create constraints with specified left-hand and right-hand side values, but with no non-zero elements.Create a temporary column object
mindoptpy.MdoCol()to store the constraints and the values of non-zero elements sequentially.Finally, call
mindoptpy.MdoModel.add_var()to create new variables with their corresponding objective function coefficients, non-zero elements in the column vector, lower and upper bounds, variable names, and variable types.
For more information, see the V0.x documentation. For a list of model attributes, see the V0.x documentation.
Method 3: Modeling languages MindOpt APL, AMPL, Pyomo, PuLP, and JuMP
The advantage of using a modeling language is that its API lets you build models that can easily be switched between different solver versions.
MindOpt supports several common modeling tools, including the following:
1. MindOpt APL
Support for MindOpt APL, a modeling language developed by the MindOpt team, was introduced in 2022.
You can use the modeling language and solver for free in your browser on the MindOpt online modeling and solving platform. The platform also includes case studies to help you get started quickly. No software installation is required. You can open your browser to use it.
For more syntax documentation, see More.
2. AMPL
Before using AMPL to call MindOpt, you must install MindOpt and AMPL. The `mindoptampl` application is located in the \bin\mindoptampl directory of the installation package. `mindoptampl` provides configurable parameters. You can use the AMPL option command to set the mindoptampl_options parameter. For example:
ampl: option mindoptampl_options 'numthreads=4 maxtime=1e+4';For more information and examples, see More.
3. CVXPY
Before using CVXPY to call MindOpt, you must install MindOpt and CVXPY. To call the MindOpt solver's CVXPY API, you must first import the mindopt_conif.py and mindopt_qpif.py interface files. Import these files in your Python code as follows:
from mindopt_conif import *
from mindopt_qpif import *For more information and examples, see More.
4. Pyomo
Before using Pyomo to call MindOpt, you must install MindOpt and Pyomo. To call the MindOpt solver's Pyomo API, you must use the mindopt_pyomo.py interface file. The MindOpt Pyomo interface inherits from Pyomo's DirectSolver class. The implementation code is in the \lib\pyomo\mindopt_pyomo.py file of the installation package. Import this file in your Python code as follows:
from mindopt_pyomo import MindoptDirectFor more information and examples, see More.
5. PuLP
Before using PuLP to call MindOpt, you must install MindOpt and PuLP. To call the MindOpt solver's PuLP API, you must use the mindopt_pulp.py interface file. The MindOpt PuLP interface inherits from PuLP's LpSolver class. The implementation code is in the \lib\pulp\mindopt_pulp.py file of the installation package. Import this file in your Python code as follows:
from mindopt_pulp import MINDOPTFor more information and examples, see More.
6. JuMP
JuMP is an open source modeling tool based on the Julia programming language. Before using JuMP to call MindOpt, you must install MindOpt, Julia, JuMP, and AmplNLWriter. Call the JuMP API to create a modeling object and specify `mindoptampl` as the solver.
model = Model(() -> AmplNLWriter.Optimizer(mindoptampl))For more information, see More.
Parameter settings for solving
You can set input parameters when you run the solver. For V1.x documentation, see the Parameters chapter. For example, you can set the maximum solving time for the solver using "MaxTime". For V0.x documentation, see the Optional Input Parameters chapter.
Reference for computing device configuration: Characteristics of different algorithms for LP solving
When you configure machine resources, the amount of resources consumed varies based on the problem structure and the selected algorithm. You should test and select the configuration as needed.
For LP solving, we currently provide the Simplex, Interior-Point Method (IPM), and Concurrent optimization algorithms. The execution flow is shown in the "Execution flow" image below. The Concurrent algorithm is selected by default. You can set the "Method" parameter to select a different algorithm.
The differences between these three algorithms are as follows:
Simplex | Interior-Point Method (IPM) | Concurrent (Simultaneous Optimization) | |
Characteristics | - Generally less sensitive to numerical issues - Consumes less memory - Supports warm-start | - More sensitive to numerical issues - Consumes 2 to 10 times more memory than the Simplex method - Does not support warm-start - May be more suitable for large-scale problems | - Optimizes using both methods simultaneously, consuming more memory - More robust - When solving a new category of problems, you can try this method first to determine whether the Simplex or IPM method is more suitable. This helps with future algorithm selection. |
Computing device requirements Requirements can vary significantly between problems. Use actual test results as the standard. The following lab test values are for reference only: | |||
When the number of constraints is 43,200 and the number of non-zero elements is 1,038,761 | Tested maximum memory usage is 350 MB | Tested maximum memory usage is 620 MB | Tested maximum memory usage is 920 MB |
When the number of constraints is 986,069 and the number of non-zero elements is 4,280,320 | Tested maximum memory usage is 1250 MB | Tested maximum memory usage is 1500 MB | Tested maximum memory usage is 1650 MB |
When the number of constraints is 4,284 and the number of non-zero elements is 11,279,748 | Tested maximum memory usage is 2050 MB | Tested maximum memory usage is 5200 MB | Tested maximum memory usage is 5200 MB |
When the number of constraints is 22,117 and the number of non-zero elements is 20,078,717 | Tested maximum memory usage is 3400 MB | Tested maximum memory usage is 5600 MB | Tested maximum memory usage is 8300 MB |
- Memory consumption depends on the problem's form, scale, and sparsity. To estimate memory resources in advance, you can first calculate the memory consumption based on the problem's scale and sparsity. Then, multiply that value by a certain factor to obtain an estimated value for reserved memory resources.
Obtaining solution results
Command line execution
When you run the solver from the command line, it prints the output of the solving process and a summary of the results. It also generates .bas and .sol result files with the same name in the same directory as the problem file.
The following figure shows that after you run the mindopt afiro.mps command, the afiro.bas and afiro.sol files are generated in the folder. The .bas file saves the basis, and the .sol file saves the optimal objective value and the solution for the variable values.

API solving and result retrieval
The APIs for V1.x and later are mostly different from the APIs for V0.x. Ensure that you are using the correct version.
V1.x
After you input the problem to be solved, call the optimize() API to solve it. For example, the Python command is model.optimize().
After solving, you can call APIs to retrieve the results. The following examples use Python:
Call
model.statusto retrieve the solution status. Possible statuses include UNKNOWN, OPTIMAL, INFEASIBLE, UNBOUNDED, INF_OR_UBD, and SUB_OPTIMAL. For example,MDO.OPTIMALin Python.Use
model.objvalto retrieve the objective value.You can also call
model.getAttr(MDO.Attr.PrimalObjVal)to retrieve other model attribute values. Similarly:SolutionTime: Total running time in secondsDualObjVal: Dual objective valueColBasis: Basis of the primal solution
Call
var.Xto retrieve the solution for a variable.For a list of more solution attributes, see More.
For complete code examples, see the `example` folder in the installation package, the documentation at More, or the examples chapter in each language's API documentation, such as the Python examples.
V0.x
After you input the problem to be solved, call the solveProb API to solve it. For example, the Python command is model.solve_prob().
After solving, you can call APIs to retrieve the results. The following examples use Python:
Call
model.display_results()to print the results.Call
model.get_status()to retrieve the solution status.Call
model.get_real_attr("PrimalObjVal")to retrieve the primal objective value. Similarly:"DualObjVal": Dual objective value"PrimalSoln": Primal solution"ColBasis": Basis of the primal solutionFor a list of more solution attributes, see the V0.x documentation
For complete code examples, see the `example` folder in the installation package or the documentation.
Solution analysis tools and advanced modeling techniques
Infeasibility analysis for constraints
During the modeling and solving process, you may encounter infeasible problems caused by conflicting constraints. Analyzing the infeasible problem and identifying the key constraints that cause the conflict can significantly help with modeling. A minimal subset of constraints that causes the problem to be infeasible is called an irreduciable infeasible system (IIS).
MindOpt provides an API to compute an IIS. If a problem is "INFEASIBLE", you can use the compute IIS API to analyze the infeasible problem. For example, you can modify or remove the constraints in the IIS to make the optimization problem feasible.
The following is an example of how to call the IIS Python interface:
V1.x
if model.status == MDO.INFEASIBLE or model.status == MDO.INF_OR_UBD:
idx_rows, idx_cols = model.compute_iis()For complete instructions on computing an IIS, see More.
V0.x
status_code, status_msg = model.get_status()
if status_msg == "INFEASIBLE":
idx_rows, idx_cols = model.compute_iis()For complete instructions on computing an IIS, see the V0.x documentation.
Callback
MindOpt uses the classic branch-and-bound method to solve MIP problems. The callback feature lets you track the solving process and make decisions to guide the solver, including the following:
Adding cutting planes to prune branches that will not contain the optimal solution.
Intervening in MindOpt's branch selection strategy to control the node bisection method and traversal order.
Adding custom feasible solutions (such as solutions obtained through a heuristic algorithm). A good feasible solution can improve MindOpt's solving efficiency.
You can create a callback function as follows:
def callback(model, where):For complete instructions on callbacks, see More.
Solver parameter tuning
MindOpt Tuner can also perform hyperparameter optimization for the solver. You can provide data from your business scenario and use MindOpt Tuner. After parameter tuning, you can obtain a faster solver customized for your business scenario. Some features are currently available on the MindOpt cloud platform.
AI engineer-assisted modeling
An AI engineer is an AI robot built on a Large Language Model (LLM) and integrated with knowledge of domain-specific software tools to provide basic technical consultation. MindOpt Copilot is an AI engineer that helps you use MindOpt technology to solve mathematical optimization problems. It can be used for technical consultation in the field of mathematical optimization.
Currently, the MindOpt Copilot AI engineer supports tools such as the MindOpt Solver and the MindOpt APL modeling language. It communicates through natural language and tabular data to automatically perform tasks based on your business problems. These tasks include mathematical modeling, formulating mathematical equations, writing code, and calling MindOpt software to solve problems. It can also generate projects from the text, mathematical formulas, and code it produces, which you can quickly import into your development projects.
First launched in September 2023, it is available on the MindOpt cloud platform.
Other features
Data masking
The MindOpt command line includes the --sanitize option, which can generate a masked model file. This makes it convenient to send data for technical exchanges or for solver parameter tuning and improvement.
Solver execution flow
MindOpt execution flow:
Different optimization problems have different solving methods, but the overall flow is similar. The following is an example of the call flow for an LP problem. During the process, you can set certain parameters.

Complete APIs and call methods
For complete instructions, see the MindOpt User Guide - Full Version
The table of contents is as follows: