4.1. Command Line

This section introduces how to use the MindOpt command-line tool to solve optimization problems. Before using it, users must first set the environment variables; for detailed instructions on setting environment variables, please refer to Installation Instructions.

4.1.1. Brief Description

The call format of the MindOpt command-line tool is as follows:

mindopt <filename> [options]
  • <filename>: Used to set the path of the optimization problem model file.

  • options: Used for solver parameter settings. For a detailed introduction to the parameters, please refer to the Parameters section.

Other command-line instructions options:

MindOpt [options]

Description

-h (or - -help)

list options

-v (or - -version)

print release version

-d (or - -disable_file_output)

disable solution (.bas and .sol files) output

-r (or - -relax)

relax all integrality requirements

-c (or - -check_license)

run license diagnostic tool

- -sanitize

desensitize the optimization model files

- -undo_sanitize

recover the model which has been desensitized

4.1.2. An Example

The following example uses the command-line tool to solve the sample problem afiro.mps in the installation path <MDOHOME>examples/data:

cd <MDOHOME>/examples/data
mindopt afiro.mps

The output after executing the command is as follows:

MindOpt Version 0.25.0 (Build date: 20230706)
Copyright (c) 2020-2023 Alibaba Cloud.

Start license validation (current time : 07-JUL-2023 02:38:36).
License validation terminated. Time : 0.002s

Reader started. File    : mindopt/0.25.0/examples/data/afiro.mps
Reader terminated. Time : 0.002s

Model summary.
 - Num. variables     : 32
 - Num. constraints   : 27
 - Num. nonzeros      : 83
 - Bound range        : [4.4e+01,5.0e+02]
 - Objective range    : [3.2e-01,1.0e+01]
 - Matrix range       : [1.1e-01,2.4e+00]

Presolver started.
Presolver terminated. Time : 0.004s

Simplex method started.
Model fingerprint: =Y2dhV2dudXY

    Iteration       Objective       Dual Inf.     Primal Inf.     Time
            0     0.00000e+00      2.9000e+00      0.0000e+00     0.01s
            5    -4.64753e+02      0.0000e+00      0.0000e+00     0.01s
Postsolver started.
Simplex method terminated. Time : 0.004s

Optimizer summary.
 - Optimizer used     : Simplex method
 - Optimizer status   : OPTIMAL
 - Total time         : 0.014s

Solution summary.       Primal solution
 - Objective          : -4.6475314286e+02

4.1.3. Input File Format

The MindOpt command line supports the following optimization model input formats:

  • .mps format

  • .lp format

  • .qps format

  • .dat-s format

These formats were originally designed for (mixed integer) linear programs and have now been extended to support quadratic cone optimization. For the specifications of the .mps format and the .lp format, please read MPS Format and LP Format. The .nl format model file can be called using the MindOpt modeling language application mindoptampl, see Install mindoptampl.

Warning

Users should follow strict specifications regarding the naming of the LP format and the MPS format, otherwise errors are likely to occur and are not easy to troubleshoot.
  • Naming specifications for the LP format Naming Specifications, include: the first letter cannot be a number, period, or the letters e and E, etc. Users need to be careful when entering variable names or constraint names using the API (see API).

  • If the naming format is not compliant when using MindOpt to model and generate MPS or LP files, MindOpt will output with default naming.

  • The length of variable names or constraint names cannot exceed 160 char.

  • Calculation symbols such as “+-” cannot be included in variable names or constraint names, otherwise the solver may treat these symbols as calculation symbols rather than variable names, resulting in parsing errors.

  • For the sake of stability, Chinese characters should be avoided as much as possible in variable names or constraint names.

Note

MindOpt currently also supports model files in the following compressed file formats:

That is, MindOpt can directly read .mps.gz files and .mps.bz2 files.

4.1.4. Parameter Settings

Users can modify the value of parameter <parameter name> to <parameter value> using the following command format:

<parameter name>=<parameter value>

For example, the following example sets the optimization method to Primal Simplex Method by modifying the parameter Method and limits the number of iterations to 10000 by modifying the parameter SPX/MaxIterations when solving the afiro.mps problem.

mindopt afiro.mps Method=0 SPX/MaxIterations=10000

For details on the parameters, please refer to the Parameters section.

4.1.5. Data Desensitization

The purpose of the --sanitize and --undo_sanitize interfaces is to desensitize and restore model files. The following table illustrates such a data desensitization function.

Before sanitization

After sanitization

NAME AFIRO

NAME Prob0001 FREE

ROWS

ROWS

E ToTalR

E R00000001

E StaffR10

E R00000002

L WorkX05

L R00000003

L WorkX21

L R00000004

E WorkR12

E R00000005

E SkillR13

E R00000006

L SkillX17

L R00000007

L SkillX18

L R00000008

L SkillX19

L R00000009

L GenderX20

L R0000000A

E GenderR19

E R0000000B

E GenderR20

E R0000000C

COLUMNS

COLUMNS

CostX01 WorkX05 .301 R09 -1.

C000001 R00000003 0.301

CostX02 SkillR13 -1.06 X05 1.

C000002 R00000006 -1.06

CostX03 SkillX18 -1. R09 1.

C000003 R00000008 -1

CostX04 GenderR20 -.4

C000004 R0000000C -0.4

The file formats supported by this interface include:

  • MPS type: The file extension must be .mps, .mps.gz, or .mps.bz2.

  • LP type: The file extension must be .lp, .lp.gz, or lp.bz2.

Use the following command-line instruction to desensitize the model file:

mindopt afiro.mps --sanitize

After desensitization, two files will be generated:

  • afiro_sanitized.mps` is the desensitized model file, where variable names, constraint names, etc. are converted into the sequential encoding form of Rxx and Cxx, clearing business-related information and retaining only numerical data.

  • afiro_mapping.json file records the correspondence between the desensitized file and the original file’s variable constraints.

After desensitization, the file can be restored to the original file using the afiro_mapping.json file. Place the two files in the same directory and then execute the following command-line instruction:

mindopt afiro_mapping.json --undo_sanitize

The file afiro_sanitized_undo_sanitized.mps generated by the command is consistent with the original problem file afiro.mps.