7.2. AMPL

AMPL (A Mathematical Programming Language) is an algebraic modeling language designed to simplify complex optimization problems into abstract algebraic expressions. Users only need to focus on the construction of the algebraic model, and then import data separately after the model is completed. This not only speeds up the development, but also effectively reduces the possibility of model input errors.

Currently, MindOpt can solve Linear Programming models constructed by AMPL on Windows/Linux/macOS platforms. For more information about AMPL, please refer to AMPL official document.

In this section we describe how to use MindOpt’s mindoptampl application to solve AMPL models.

7.2.1. Install mindoptampl

The mindoptampl application is automatically generated during MindOpt installation. For installation and configuration of MindOpt, please refer to Software Installation.

Verify the mindoptampl application as follows:

After MindOpt is installed, the path of mindoptampl is as follows:

<MDOHOME>\<VERSION>\<PLATFORM>\bin\mindoptampl

Users can verify whether the mindoptampl application is available with the following command line:

mindoptampl --version

If the version information of MindOpt and mindoptampl similar to the following is returned, the installation is successful:

2.0.0 (Darwin x86_64), driver(20230713), ASL(20201107)

mindoptampl supports direct command line to solve .nl format files, you can directly run the following command on the command line to solve.

mindoptampl <MDOHOME>\<VERSION>\examples\ampl\diet.nl

7.2.2. Install AMPL

Users can download and install AMPL from the official website, such as: TRY AMPL.

7.2.3. Parameters and Return Values

mindoptampl provides some configurable parameters, mindoptampl_options, that can be set through the option command of AMPL, such as:

ampl: option mindoptampl_options 'num_threads=4 max_time=3600';

All parameters supported by mindoptampl can be obtained through the following command:

mindoptampl -=

For detailed description of MindOpt parameters, please refer to Parameters.

MindOpt AMPL interface parameters

Parameters

Description

dualization

Set whether to dualize the model

enable_network_flow

Set whether to enable network simplex method

enable_stochastic_lp

Set whether to enable the detection of random LP structure, which can be accelerated when the specific problem structure is turned on

ipm_dual_tolerance

Sets the dual feasibility (relative) tolerance used by the interior point method

ipm_gap_tolerance

Set the dual gap (relative) tolerance in the interior point method

ipm_max_iterations

Set the maximum number of iterations in the interior point method

ipm_primal_tolerance

Sets the primitive feasibility (relative) tolerance used by the interior point method

max_time

Set the maximum solution time for the optimizer in seconds

method

Set the algorithm used in the optimizer

mip_allow_dual_presolve

Specify whether to enable the dual presolve method of MIP

mip_auto_configuration

Set whether to enable MIP automatic parameter configuration

mip_cutoff

Sets the cutoff value of the objective value to prevent finding solutions worse than this value

mip_detect_disconnected_components

Specify whether to enable disconnected components policy in MIP

mip_gap_abs

Set absolute MIP gap tolerance

mip_gap_rel

Set relative MIP gap tolerance

mip_integer_tolerance

Set integer decision precision in MIP solution

mip_linearization_big_m

Set the maximum coefficient when rearranging nonlinear functions in MIP

mip_max_stalling_nodes

Set the maximum number of nodes that are allowed to stall

mip_max_nodes

Set maximum node limit in MIP

mip_max_sols

Set the maximum number of solutions in MIP

mip_objective_tolerance

Set the comparison accuracy of objective value in MIP solution

mip_root_parallelism

Set the maximum number of concurrent threads allowed by the root node in the MIP solver

mip_solution_pool_size

Set the maximum size of the solution pool

num_threads

Set the maximum number of threads used when optimizing the solution

presolve

Set presolver level

print

Set print level

spx_crash_start

Set whether to use the initial basis solution generation method in the simplex method

spx_column_generation

Set whether to use column generation in the simplex method

spx_dual_pricing

Set dual pricing strategy in simplex method

spx_dual_tolerance

Sets the dual feasibility (relative) tolerance used by the simplex method

spx_max_iterations

Set the maximum number of iterations in the simplex method

spx_primal_pricing

Set primitive pricing strategy in simplex method

spx_primal_tolerance

Set the primitive feasibility tolerance used by the simplex method

wantsol

Set whether to return the result (without -AMPL), 1 write the .sol file, 2 print the value of the variable, 8 do not print the solution information.

When MindOpt finishes computing, status information will be returned to AMPL in the form of exit code. Users can obtain status information in the following ways:

ampl: display solve_result_num;

7.2.4. An Example of AMPL Calling MindOpt

The following will take the Diet problem as an example to illustrate how to create an AMPL model and call the mindoptampl application to solve it.

The Diet question uses data from the following two tables: Prices of foods and Nutrition of foods .

Prices of foods

Food

Price

BEEF

3.19

CHK

2.59

FISH

2.29

HAM

2.89

MCH

1.89

MTL

1.99

SPG

1.99

TUR

2.49

Nutrition of foods

Food

A

C

B1

B2

BEEF

60

20

10

15

CHK

8

0

20

20

FISH

8

10

15

10

HAM

40

40

35

10

MCH

15

35

15

15

MTL

70

30

15

15

SPG

25

50

25

15

TUR

60

20

15

10

The goal of the Diet problem is to match the food combination that satisfies the nutritional needs at the lowest price; the algebraic mathematical model of the problem is as follows:

\[\begin{split}\begin{eqnarray} &\min & \sum_{j \in J} \mbox{cost}_j \times \mbox{buy}_j \\ &\mbox{s.t.} & \mbox{n_min}_i \leq \sum_{j \in J} \mbox{amt}_{i,j} \times \mbox{buy}_j \leq \mbox{n_max}_i, \forall i \in I, \\ & & \mbox{f_min}_j \leq \mbox{buy}_j \leq \mbox{f_max}_j, \forall j \in J. \end{eqnarray}\end{split}\]

Here,

  • \(\mbox{buy}\) is the decision variable,

  • \(\mbox{f_min}\) and \(\mbox{f_max}\) are the lower and upper bounds of \(\mbox{buy}\) respectively,

  • \(\mbox{cost}\) is the coefficient in the objective function,

  • \(\mbox{amt}\) is the constraint matrix,

  • \(\mbox{n_min}\) and \(\mbox{n_max}\) are the lower and upper bounds of the constraints, respectively.

Before using AMPL, first convert the algebraic mathematical model of the above Diet problem into the following AMPL model

  1. The abstract algebraic model diet.mod,

  2. The data file diet.dat.

Next, load the above file in AMPL and call the mindoptampl application to solve the problem:

ampl: model diet.mod;
ampl: data diet.dat;
ampl: option solver mindoptampl;
ampl: option mindoptampl_options 'numthreads=4 maxtime=1e+4';
ampl: solve;

After the solution is computed, the user can view the results through the display command of AMPL:

ampl: display Buy;
Buy [*] :=
BEEF   0
CHK    0
FISH   0
HAM    0
MCH    46.6667
MTL    0
SPG    0
TUR    0
;