AMPL is a modeling language for specifying linear and nonlinear optimization models in a natural way. AMPL also makes it easy to solve the problem and e.g. display the solution or part of it.
We will not discuss the specifics of the AMPL language here but instead refer the reader to [14] and the AMPL website http://www.ampl.com.
AMPL cannot solve optimization problems by itself but requires a link to an appropriate optimizer such as MOSEK. The MOSEK distribution includes an AMPL link which makes it possible to use MOSEK as an optimizer within AMPL.
The MOSEK distribution by default comes with the AMPL shell installed. To invoke the AMPL shell type:
mampl
It is possible to specify problems in AMPL that cannot be solved by MOSEK. The optimization problem must be a smooth convex optimization problem as discussed in Section 9.5.
In many instances, you can successfully apply MOSEK simply by specifying the model and data, setting the solver option to MOSEK, and typing solve. First to invoke the AMPL shell type:
mampl
when the AMPL shell has started type the commands:
ampl: model diet.mod; ampl: data diet.dat; ampl: option solver mosek; ampl: solve;
The resulting output is:
MOSEK finished.
Problem status - PRIMAL_AND_DUAL_FEASIBLE
Solution status - OPTIMAL
Primal objective - 14.8557377
Dual objective - 14.8557377
Objective = Total_Cost
The AMPL parameter solve_result_num is used to indicate the outcome of the optimization process. It is used as follows
ampl: display solve_result_num
Please refer to table 5.1 for possible values of this parameter.
|
The MOSEK optimizer has options and parameters controlling such things as the termination criterion and which optimizer is used. These parameters can be modified within AMPL as shown in the example below:
ampl: model diet.mod; ampl: data diet.dat; ampl: option solver mosek; ampl: option mosek_options ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex \ ampl? msk_ipar_sim_max_iterations = 100000'; ampl: solve;
In the example above a string called mosek_options is created which contains the parameter settings. Each parameter setting has the format
parameter name = value
where “parameter name” can be any valid MOSEK parameter name. See Appendix H for a description of all valid MOSEK parameters.
An alternative way of specifying the options is
ampl: option mosek_options ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex' ampl? ' msk_ipar_sim_max_iterations = 100000';
New options can also be appended to an existing option string as shown below
ampl: option mosek_options $mosek_options ampl? ' msk_ipar_sim_print_freq = 0 msk_ipar_sim_max_iterations = 1000';
The expression $mosek_optionsexpands to the current value of the option. Line two in the example appends an additional value msk_ipar_sim_max_iterations to the option string.
MOSEK also recognizes the outlev option which controls the amount of printed output. 0 means no printed output and a higher value means more printed output. An example of setting outlev is as follows:
ampl: option mosek_options 'outlev=2';
MOSEK recognize the option wantsol. We refer the reader to the AMPL manual [14] for details about this option.
The MOSEK optimizer can produce three types of solutions: basic, integer, and interior point solutions. For nonlinear problems only an interior solution is available. For linear optimization problems optimized by the interior-point optimizer with basis identification turned on both a basic and an interior point solution are calculated. The simplex algorithm produces only a basic solution. Whenever both an interior and a basic solution are available, the basic solution is returned. For problems containing integer variables, the integer solution is returned to AMPL.
Frequently, a sequence of optimization problems is solved where each problem differs only slightly from the previous problem. In that case it may be advantageous to use the previous optimal solution to hot-start the optimizer. Such a facility is available in MOSEK only when the simplex optimizer is used.
The hot-start facility exploits the AMPL variable suffix sstatus to communicate the optimal basis back to AMPL, and AMPL uses this facility to communicate an initial basis to MOSEK. The following example demonstrates this feature.
ampl: model diet.mod; ampl: model diet.dat; ampl: option solver mosek; ampl: option mosek_options ampl? 'msk_ipar_optimizer = msk_optimizer_primal_simplex outlev=2'; ampl: solve; ampl: display Buy.sstatus; ampl: solve;
The resulting output is:
MOSEK 1.4: Accepted: msk_ipar_optimizer = MSK_OPTIMIZER_PRIMAL_SIMPLEX
ITER DEGITER FEAS DOBJ
0 0 2.805e+003 0.0000000000e+000
6 0 0.000e+000 1.4855737705e+001
7 0 0.000e+000 1.4855737705e+001
Return code - 0 (MSK_RES_OK)
MOSEK finished.
Problem status - PRIMAL_AND_DUAL_FEASIBLE
Solution status - OPTIMAL
Primal objective - 14.8557377
Dual objective - 14.8557377
Objective = Total_Cost
Buy.sstatus [*] :=
'Quarter Pounder w/ Cheese' bas
'McLean Deluxe w/ Cheese' low
'Big Mac' low
Filet-O-Fish low
'McGrilled Chicken' low
'Fries, small' bas
'Sausage McMuffin' low
'1% Lowfat Milk' bas
'Orange Juice' low
;
MOSEK 1.4: Accepted: msk_ipar_optimizer = MSK_OPTIMIZER_PRIMAL_SIMPLEX
ITER DEGITER FEAS DOBJ
0 0 0.000e+000 1.4855737705e+001
0 0 0.000e+000 1.4855737705e+001
1 0 0.000e+000 1.4855737705e+001
Return code - 0 (MSK_RES_OK)
MOSEK finished.
Problem status - PRIMAL_AND_DUAL_FEASIBLE
Solution status - OPTIMAL
Primal objective - 14.8557377
Dual objective - 14.8557377
Objective = Total_Cost
Please note that the second solve takes fewer iterations since the previous optimal basis is reused.
MOSEK can calculate sensitivity information for the objective and constraints. To enable sensitivity information set the option:
sensitivity = 1
Results are returned in variable/constraint suffixes as follows:
For ranged constraints sensitivity information is returned only for the lower bound.
The example below returns sensitivity information on the diet model.
model diet.mod; data diet.dat; options solver mosek; option mosek_options 'sensitivity=1'; solve; #display sensitivity information and current solution. display _var.down,_var.current,_var.up,_var; #display sensitivity information and optimal dual values. display _con.down,_con.current,_con.up,_con;
The resulting output is:
Return code - 0 [MSK_RES_OK] MOSEK finished. (interior-point iterations - 11, primal simplex iterations - 0 dual simplex iterations - 0) Problem status : PRIMAL_AND_DUAL_FEASIBLE Solution status : OPTIMAL Primal objective : 88.2 Dual objective : 88.2 suffix up OUT; suffix down OUT; suffix current OUT; : _var.down _var.current _var.up _var := 1 1.97182 3.19 Infinity 0 2 2.49818 2.59 Infinity 0 3 1.25636 2.29 Infinity 0 4 1.31455 2.89 Infinity 0 5 0.426429 1.89 1.94918 46.6667 6 1.89 1.99 2.44 0 7 1.90818 1.99 Infinity 0 8 1.35091 2.49 Infinity 0 ; : _con.down _con.current _con.up _con := 1 700 700 3266.67 0.00181818 2 -Infinity 700 700 0 3 700 700 700 0.124182 4 -Infinity 700 1633.33 0 ;
AMPL can generate a data file which contains all the relevant problem information. Afterwards this data file can be loaded into MOSEK and the problem can be solved.
The following example demonstrate this feature.
mampl -obdiet prob.mod mosek prob.nl outlev=1 -a
First AMPL is used to create the prob.nl data file and next MOSEK is used to solve the problem. Note that the -a command line option indicates that MOSEK is invoked in AMPL mode. When MOSEK is invoked in AMPL mode the normal MOSEK command line options should appear after the -a option except for the file name which should be the first argument. As the above example demonstrates MOSEK accepts command line options as specified by the AMPL “convention”. Which command line arguments MOSEK accepts in AMPL mode can be viewed by executing
mosek -= -a
To convert an AMPL file to one of the file formats MOSEK supports (e.g MPS) use the command below:
mosek prob.nl -a -out prob.mps -x
.