Running BONMIN

On an .nl file / From AMPL / priorities and SOS in AMPL / From GAMS / From a C++ Program /

References

Running BONMIN

BONMIN can be run

In this page, we give some details about the various ways to run BONMIN.

On a .nl file

BONMIN can read a .nl file which could be generated by AMPL (for example mytoy.nl in the Bonmin-dist/Bonmin/test subdirectory). The command line takes just one argument which is the name of the .nl file to be processed.

For example, if you want to solve mytoy.nl, from the Bonmin-dist directory, issue the command:

 
bonmin test/mytoy.nl  

From AMPL

To use BONMIN from AMPL you just need to have the directory where the bonmin executable is in your $PATH and to issue the command

 
option solver bonmin;  

in the AMPL environment. Then the next solve will use BONMIN to solve the model loaded in AMPL. After the optimization is finished, the values of the variables in the best-known or optimal solution can be accessed in AMPL. If the optimization is interrupted with <CTRL-C> the best known solution is accessible (this feature is not available in Cygwin).

Example AMPL model

A simple AMPL example model follows:

 
   # An AMPL version of toy  
 
   reset;  
 
   var x binary;  
   var z integer >= 0 <= 5;  
   var y{1..2} >=0;  
   minimize cost:  
       - x - y[1] - y[2] ;  
 
   subject to  
       c1: ( y[1] - 1/2 )^2 + (y[2] - 1/2)^2 <= 1/4 ;  
       c2: x - y[1] <= 0 ;  
       c3: x + y[2] + z <= 2;  
 
   option solver bonmin; # Choose BONMIN as the solver (assuming  
                         # that bonmin is in your PATH)  
 
   solve;                # Solve the model  
   display x;  
   display y;  

(This example model can be found in the BONMIN package in the subdirectory Bonmin/examples/amplExamples/.)

Setting up branching priorities, directions and declaring SOS1 constraints in AMPL

Branching priorities, branching directions and pseudo-costs can be passed using AMPL suffixes. The suffix for branching priorities is "priority" (variables with a higher priority will be chosen first for branching), for branching direction is "direction" (if direction is 1 the branch is explored first, if direction is -1 the branch is explored first), for up and down pseudo costs "upPseudoCost" and "downPseudoCost" respectively (note that if only one of the up and down pseudo-costs is set in the AMPL model it will be used for both up and down).

For example, to give branching priorities of 10 to variables y and 1 to variable x and to set the branching directions to explore the upper branch first for all variables in the simple example given, we add before the call to solve:

 
suffix priority IN, integer, >=0, <= 9999;  
y[1].priority := 10;  
y[2].priority := 10;  
x.priority := 1;  
 
suffix direction IN, integer, >=-1, <=1;  
y[1].direction := 1;  
y[2].direction := 1;  
x.direction := 1;  

SOS Type-1 branching is also available in BONMIN from AMPL. We follow the conventional way of doing this with suffixes. Two type of suffixes should be declared:

suffix sosno IN, integer, >=1;  # Note that the solver assumes  
                                # that these values are positive  
                                # for SOS Type 1  
suffix ref IN;

Next, suppose that we wish to have variables

var X {i in 1..M, j in 1..N} binary;

and the “convexity” constraints:

subject to Convexity {i in 1..M}:  
   sum {j in 1..N} X[i,j] = 1;

(note that we must explicitly include the convexity constraints in the AMPL model).

Then after reading in the data, we set the suffix values:

 
# The numbers ‘val[i,j]’ are chosen typically as  
#     the values ‘represented’ by the discrete choices.  
let {i in 1..M, j in 1..N} X[i,j].ref := val[i,j];  
 
# These identify which SOS constraint each variable belongs to.  
let {i in 1..M, j in 1..N} X[i,j].sosno := i;

From GAMS

Thanks to the GAMSlinks project, Bonmin is available in GAMS since release 22.5 of the GAMS modeling system. The system is available for download from GAMS. Without buying a license it works as a demo with limited capabilities. Documentation for using BONMIN in GAMS is available here.

From a C/C++ program

BONMIN can also be run from within a C/C++ program if the user codes the functions to compute first- and second-order derivatives. An example of such a program is available in the subdirectory CppExample of the examples directory. For further explanations, please refer to this example and to the reference manual.