All Products
Search
Document Center

Optimization Solver:User Manual of Optimization Solver

Last Updated:Feb 01, 2024

This topic describes how Optimization Solver is called and how problems are input, and lists APIs and operations of Optimization Solver.

Note

Optimization Solver has a large number of APIs and operations, and new APIs and operations are frequently added. This topic provides a list of existing APIs and operations. For more information about these APIs and operations, see MindOpt User Manual.

If you are using the V0.x, please refer to the V0.x User Manual.

How to call Optimization Solver

Before you use Optimization Solver, make sure that you have downloaded and installed the Solver SDK and obtained the permissions to use Optimization Solver. For information about how to perform these operations, see Activate and use the service and Download and install the latest Optimization Solver SDK.

The following examples demonstrate how to call Optimization Solver. For more information, see Call methods.

Examples of calling Optimization Solver by using CLI

Assume that you have installed Optimization Solver in the directory specified by the environment variable $MINDOPT_HOME according to the installation document. In Linux or macOS, run the following command to call Optimization Solver:

mindopt $MINDOPT_HOME/examples/data/afiro.mps

In Windows, run the following command to call Optimization Solver:

mindopt %MINDOPT_HOME%\examples\data\afiro.mps

Examples of calling Optimization Solver in Python, Java, C++, C# and C languages

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::ends;
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)}");
}

For information about the complete sample code, see Call methods.

Types of optimization problems that can be solved

Optimization Solver of the current version can solve problems of the following types:

  • Linear programming (LP): Optimization Solver is capable of solving LP problems. It supports the primal or dual simplex method and the interior-point method (IPM), and can solve a large number of network flow optimization problems.

  • Integer programming: Optimization Solver supports the branch-and-cut solver for solving mixed integer linear programming (MILP) problems.

  • Nonlinear programming: Optimization Solver can solve convex quadratic programming (QP) problems and semidefinite programming (SDP) problems.

Methods of inputting optimization problems

Optimization problems can be input by using files and external modeling tools, and by calling API operations.

Method 1: Input problems by using files

  • Optimization Solver supports MPS and LP files, including files with the extensions .mps and .lp, as well as their compressed files such as .mps.gz and .mps.bz2 files.

  • .dat-s files. For example, you can input SDP problems by using .dat-s files.

  • .qps format. For example, QP problems.

  • The mindoptampl module supports .nl files. For example, you can enter mindoptampl filename.nl on CLI.

For more information, see Input file format: mps/lp/dat-s.

Method 2: Input problems by calling API operations

You can input a problem by calling multiple API operations.

  • Example of inputting a problem by row in Python

    • Call mindoptpy.Model.modelsense = MDO.MINIMIZE to set the target obj function to Minimization.

    • Call mindoptpy.Model.addVar() to add four optimization variables and define the upper bound, lower bound, objective coefficient, name, and type of the variables.

    • Call mindoptpy.Model.addConstrs() to add constraints.

  • Example of inputting a problem by column in Python

    • Call mindoptpy.Model.modelsense = MDO.MAXIMIZE to set the target obj function to Minimization.

    • Call mindoptpy.Model.addConstrs() to create a constraint with the specified left-hand and right-hand values (no non-zero elements).

    • Call mindoptpy.Model.Column() to create a temporary column object for holding the values of the constraint and non-zero elements in order.

    • Call mindoptpy.Model.addVar() to create a variable, including the corresponding objective function coefficient, non-zero elements in the column vector, the lower and upper bounds of the variable, the variable name, and the variable type.

For more information about how to build models and solve problems, see Modeling and Optimization. For information about attributes, see Attributes. And more examples.

Method 3: Input problems by using modeling tools such as AMPL, Pyomo, PuLP, and MindOpt APL

This section describes the modeling tools that are supported by Optimization Solver.

1. MindOpt APL

MindOpt Algebraic Programming Language (MindOpt APL or MAPL) is an efficient algebraic modeling language for optimization. It supports a variety of solvers.

2. AMPL

Before you use AMPL to call Optimization Solver, make sure that you have installed Optimization Solver and AMPL. The mindoptampl module is stored in \bin\mindoptampl of the installation package. The mindoptampl module provides some 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, see AMPL.

3. Pyomo

Before you use Pyomo to call Optimization Solver, make sure that you have installed Optimization Solver and Pyomo. The mindopt_pyomo.py file is required when the Pyomo API is used to call Optimization Solver. The Pyomo API is inherited from the DirectSolver class of Pyomo and its implementation code is included in \lib\pyomo\mindopt_pyomo.py of the installation package. You need to run the following command to import the mindopt_pyomo.py file to Python code:

from mindopt_pyomo import MindoDirect

For more information, see Pyomo.

4. PuLP

Before you use PuLP to call Optimization Solver, make sure that you have installed Optimization Solver and PuLP. The mindopt_pulp.py file is required when the PuLP API is used to call Optimization Solver. The PuLP API is inherited from the LpSolver class of PuLP and its implementation code is included in \lib\pulp\mindopt_pulp.py of the installation package. You need to run the following command to import the mindopt_pulp.py file to Python code:

from mindopt_pulp import MINDOPT

For more information, see PuLP.

5. JuMP

JuMP is an open-source modeling tool based on the Julia programming language. Before you use PuLP to call Optimization Solver, make sure that you have installed MindOpt, Julia, JuMP and AmplNLWriter. Next, we need to call the JuMP API to create a model object, specifying mindoptampl as the solver.

model = Model(() -> AmplNLWriter.Optimizer(mindoptampl))

For more information, see JuMP.

Parameter settings for solving problems

You can set input parameters to run the Solver. For more information about how to set the parameters, see Optional input parameters. For example, you can set the MaxTime parameter to the maximum time allowed for the Solver to solve a problem.

Computing device configuration reference (use different algorithms for solving LP problems)

The device resources consumed vary based on the problem structure and algorithm selected. You need to select an algorithm based on your business requirements.

Optimization Solver can solve LP problems by using the simplex method, IPM, and concurrent optimization method. When Optimization Solver solves a problem according to the process illustrated in the following section, the concurrent optimization method is selected by default. You can set the "Method" parameter to a specific algorithm.

The following table describes the differences between the three algorithms.

Simplex method

IPM

Concurrent optimization method

Features

- This algorithm has low sensitivity to numerical values.

- This algorithm consumes less memory.

- This algorithm supports warm start.

- This algorithm has high sensitivity to numerical value.

- This algorithm consumes 2 to 10 times more memory than the simplex method.

- This algorithm does not support warm start.

- This algorithm may be more applicable to scenarios in which a large number of problems need to be solved.

- Two methods are concurrently used to solve problems, which consumes more memory.

- This algorithm is more robust.

- When you solve a new type of problem, we recommend that you try this method first. This helps distinguish whether the simplex method or IPM is more suitable for solving this type of problem, and facilitates selection of algorithms if the same type of problem needs to be solved in the future.

Requirements for the computing device

The requirements for the computing device may vary based on the types of problems. You need to configure the computing device based on your business requirements. The following lab test values are used for reference only.

Simplex

IPM

Concurrent

Scenario 1: There are 43,200 problem constraints and 1,038,761 non-zero elements.

Maximum memory usage: 350 MB

Maximum memory usage: 620 MB

Maximum memory usage: 920 MB

Scenario 2: There are 986,069 problem constraints and 4,280,320 non-zero elements.

Maximum memory usage: 1,250 MB

Maximum memory usage: 1,500 MB

Maximum memory usage: 1,650 MB

Scenario 3: There are 4,284 problem constraints and 11,279,748 non-zero elements.

Maximum memory usage: 2,050 MB

Maximum memory usage: 5,200 MB

Maximum memory usage: 5,200 MB

Scenario 4: There are 22,117 problem constraints and 20,078,717 non-zero elements.

Maximum memory usage: 3,400 MB

Maximum memory usage: 5,600 MB

Maximum memory usage: 8,300 MB

Note

The memory usage depends on the type, size, and sparsity of problems. If you want to estimate memory usage in advance, we recommend that you calculate the memory usage based on the size and sparsity of problems, and then multiply the memory usage by a certain multiple and use the final result as the estimated value of reserved memory resources.

Obtain solving results

By using CLI

If you solve a problem by using CLI, summaries of the solving process and the solution are displayed, and .bas and .sol solution documents with the same name as the solved file are generated next to the solved file.

In the following example, the afiro.bas and afiro.sol files are generated after the mindopt afiro.mps file is executed. The .bas file holds the basis, and the .sol file holds the optimal objective value and variable values.

lQLPJwEdbd-17pzNAR7NApqwz0O66RW2UCEExUKi1cC7AA_666_286.png

By calling API operations

After you input a problem, you can call optimize() to solve the problem. For example, in Python, you can call model.optimize() to resolve the problem.

After the problem is solved, you can call relevant API operations to obtain the solving results. For example, in Python:

  • You can call model.status to obtain the solving status.

  • You can call model.objval to obtain the primal objective value.

    • You can also call model.getAttr(MDO.Attr.PrimalObjVal) to obtain the primal objective value. Similarly:

      • UseSolutionTime to obtain the total execution time in seconds.

      • Use DualObjVal to obtain the dual objective value.

      • Use ColBasis to obtain the basis of the primal solution.

  • You can call var.X to obtain the value of decision variables.

  • For more information about solution attributes, see Attributes.

For information about the complete sample code, see the example folder in the installation package, or see Modeling and optimization or examples.

Auxiliary solving analysis or Advanced Modeling Tools

Constraint infeasibility analysis

When you build a model to solve an optimization problem, the problem may be infeasible because certain constraints conflict with each other. Analyzing the infeasible problem and identifying the key conflicting constraints can help build models. The minimum subset of the constraints that make the problem infeasible is called an irreducible infeasible system (IIS).

Optimization Solver provides API operations for computing IISs. You can call an operation to analyze an infeasible problem, and modify or remove the constraints in the IIS based on the analysis results to make the problem feasible.

The following example shows how to call an API operation to compute an IIS in Python:

if model.status == MDO.INFEASIBLE or model.status == MDO.INF_OR_UBD:
    idx_rows, idx_cols = model.compute_iis()

For more information about how to compute IISs, see Analysis of constraint conflicts.

Callback

MindOpt adopts the classical branch and bound method to solve MIP problems. MindOpt provides users with callback functions to track and modify the optimization process of MIP problems. Users can use callbacks to modify the behavior of the MIP optimizer, including:

  • Add cutting planes to cut off branches that will not lead to the optimal solutions.

  • Modify the branch selection strategy of MindOpt to control node branching methods and traversal order.

  • Add feasible solutions (e.g., solutions obtained through self-implemented heuristic algorithms). A good feasible solution can improve the solving efficiency of MindOpt.

def callback(model, where):

For more information, see Callback.

MindOpt Tuner

MindOpt Tuner is a hyperparameter tuning tool. It supports automatic tuning of various open-source/commercial solvers such as MindOpt optimization solver to maximize the solver's performance on a specific problem or set of problems, including reducing solving time and optimizing the gap of the solution. Meanwhile, MindOpt Tuner can be used in conjunction with MindOpt APL modeling language, supporting parameter tuning for all the integrated solvers.

You can try it free on link.

MindOpt Copilot help you modeling and coding

MindOpt Copilot is an advanced AI solution developed from large language models, designed to assist users with "mathematical programming" problems using MindOpt technology. Tailored for both beginners and experts, it offers insightful consulting, problem modeling, and coding in the realm of mathematical programming. The platform seamlessly integrates with tools like MindOpt Solver and MindOpt APL. Additionally, with its ability to interpret natural languages and tabular data (.csv files), MindOpt Copilot can autonomously carry out mathematical modeling, generate formulas, draft code to solve specific business issues.

You can try it free on link.

Others

Data sanitize

You can use --sanitize in command-line to desensitize the model files. It change the variable names, constraint names to the sequential encoding form of Rxx and Cxx, clearing business-related information and retaining only numerical data. More.

Solving process

Solving process of Optimization Solver

The following example demonstrates how an LP problem is solved. When you solve optimization problems of other types, the specific algorithms will be automatically adapted.

Solving process

APIs and operations of Optimization Solver

For more information about APIs and operations of Optimization Solver, see MindOpt API Reference.