Debian Codegraph @

Bonmin/doc/use.tex

raw
1
2 \begin{PageSummary}
3 \PageName{Running \Bonmin}
4 \PageSection{On an .nl file}{sec:run_nl}
5 \PageSection{From AMPL}{sec:run_ampl}
6 \PageSection{priorities and SOS in AMPL}{sub_sec:prio}
7 \PageSection{From GAMS}{sec:run_gams}
8 \PageSection{From a C++ Program}{sec:run_cpp}
9 \end{PageSummary}
10
11 \begin{quickref}
12 \quickcitation{Writing \texttt{\bf .nl} files. D.M.~Gay.}{\BibPage \#Gay}
13 \quickcitation{AMPL: A Modeling Language for Mathematical
14 Programming, Second Edition, Duxbury Press Brooks Cole Publishing Co., 2003. R.~Fourer and D.M.~Gay and B.W.~Kernighan.}{\BibPage \#AMPL}
15 \end{quickref}
16
17
18 \PageTitle{Running \Bonmin}{sec:run}
19 \Bonmin\ can be run
20 \begin{itemize}
21 \item [(i)] from a command line on a {\tt .nl} file
22 (see \mycite{Gay}{Gay2005}),
23 \item [(ii)] from the modeling language \footlink{http://www.ampl.com}{\tt AMPL} (see
24 \mycite{AMPL}{Fourer2003}),
25 \item[(iii)] from the \footlink{http://www.gams.com/}{GAMS} modeling language,
26 \item [(iv)] by invoking it from a C/C++ program,
27 \item[(v)] remotely through the \footlink{http://neos.mcs.anl.gov/neos}{NEOS} web interface,
28 \item[(vi)] via the \footlink{https://projects.coin-or.org/OS}{Optimization Services} project,
29 \item[(vii)] via the MATLAB \footlink{http://www.i2c2.aut.ac.nz/Wiki/OPTI}{OPTI Toolbox}.
30 \end{itemize}
31
32 In \latexhtml{the subsections that follow}{this page}, we give some details about the
33 various ways to run \Bonmin.
34
35 \subsectionH{On a {\tt .nl} file}{sec:run_nl}
36 \Bonmin\ can read a {\tt .nl} file which could be generated by {\tt
37 AMPL} (for example {\tt mytoy.nl} in the {\tt
38 Bonmin-dist/Bonmin/test} subdirectory). The command line takes just
39 one argument which is the name of the {\tt .nl} file to be
40 processed.
41
42 For example, if you want to solve {\tt mytoy.nl}, from the {\tt
43 Bonmin-dist} directory, issue the command:
44
45 \begin{colorverb}
46 \begin{verbatim}
47
48 bonmin test/mytoy.nl
49
50 \end{verbatim}
51 \end{colorverb}
52
53 \subsectionH{From {\tt AMPL}}{sec:run_ampl}
54 To use \Bonmin\ from {\tt AMPL} you just need to have the directory where the
55 {\tt bonmin} executable is in your {\tt \$PATH} and to issue the
56 command
57
58 \begin{colorverb}
59 \begin{verbatim}
60
61 option solver bonmin;
62
63 \end{verbatim}
64 \end{colorverb}
65
66 in the {\tt AMPL} environment. Then the next {\tt solve} will
67 use \Bonmin\ to solve the model loaded in {\tt AMPL}.
68 After the optimization is finished, the values of the variables in the best-known
69 or optimal solution can be accessed in {\tt AMPL}. If the optimization is interrupted
70 with {\tt <CTRL-C>} the best known solution is accessible (this feature is not available in Cygwin).
71
72 \subsubsectionH{Example {\tt AMPL} model}{}
73 A simple {\tt AMPL} example model follows:
74
75 \begin{colorverb}
76 \begin{verbatim}
77
78 # An AMPL version of toy
79
80 reset;
81
82 var x binary;
83 var z integer >= 0 <= 5;
84 var y{1..2} >=0;
85 minimize cost:
86 - x - y[1] - y[2] ;
87
88 subject to
89 c1: ( y[1] - 1/2 )^2 + (y[2] - 1/2)^2 <= 1/4 ;
90 c2: x - y[1] <= 0 ;
91 c3: x + y[2] + z <= 2;
92
93 option solver bonmin; # Choose BONMIN as the solver (assuming
94 # that bonmin is in your PATH)
95
96 solve; # Solve the model
97 display x;
98 display y;
99
100 \end{verbatim}
101 \end{colorverb}
102 (This example model can be found in the \Bonmin\ package in the subdirectory {\tt Bonmin/examples/amplExamples/}.)
103
104 \subsubsectionH{Setting up branching priorities, directions and declaring SOS1 constraints in AMPL}{sub_sec:prio}
105 Branching priorities, branching directions and pseudo-costs can be passed using {\tt AMPL} suffixes.
106 The suffix for branching priorities is {\tt "priority"} (variables with a higher priority
107 will be chosen first for branching),
108 for branching direction is {\tt "direction"} (if direction is $1$ the $\geq$ branch
109 is explored first, if direction is $-1$ the $\leq$ branch is explored first), for up
110 and down pseudo costs {\tt "upPseudoCost"} and {\tt "downPseudoCost"} respectively
111 (note that if only one of the up and down pseudo-costs is set in the {\tt AMPL} model it will
112 be used for both up and down).
113
114 For example, to give branching priorities of $10$ to variables {\tt y} and 1 to variable {\tt x}
115 and to set the branching directions to explore the upper branch first for all variables
116 in the simple example given, we add before the call to solve:
117 \begin{colorverb}
118 \begin{verbatim}
119
120 suffix priority IN, integer, >=0, <= 9999;
121 y[1].priority := 10;
122 y[2].priority := 10;
123 x.priority := 1;
124
125 suffix direction IN, integer, >=-1, <=1;
126 y[1].direction := 1;
127 y[2].direction := 1;
128 x.direction := 1;
129
130 \end{verbatim}
131 \end{colorverb}
132
133 SOS Type-1 branching is also available in \Bonmin\ from {\tt AMPL}. We
134 follow the conventional way of doing this with suffixes.
135 Two type of suffixes should be declared:
136
137 \begin{colorverb}
138 \begin{verbatim}
139 suffix sosno IN, integer, >=1; # Note that the solver assumes
140 # that these values are positive
141 # for SOS Type 1
142 suffix ref IN;
143 \end{verbatim}
144 \end{colorverb}
145
146 Next, suppose that we wish to have variables
147
148 \begin{colorverb}
149 \begin{verbatim}
150 var X {i in 1..M, j in 1..N} binary;
151 \end{verbatim}
152 \end{colorverb}
153 and the ``convexity'' constraints:
154
155 \begin{colorverb}
156 \begin{verbatim}
157 subject to Convexity {i in 1..M}:
158 sum {j in 1..N} X[i,j] = 1;
159 \end{verbatim}
160 \end{colorverb}
161
162 (note that we must explicitly include the convexity constraints in the {\tt AMPL} model).
163
164 Then after reading in the data, we set the suffix values:
165 \begin{colorverb}
166 \begin{verbatim}
167
168 # The numbers `val[i,j]' are chosen typically as
169 # the values `represented' by the discrete choices.
170 let {i in 1..M, j in 1..N} X[i,j].ref := val[i,j];
171
172 # These identify which SOS constraint each variable belongs to.
173 let {i in 1..M, j in 1..N} X[i,j].sosno := i;
174 \end{verbatim}
175 \end{colorverb}
176
177 \subsectionH{From {\tt GAMS}}{sec:run_gams}
178 Thanks to the \footlink{http://projects.coin-or.org/GAMSlinks}{GAMSlinks} project,
179 Bonmin is available in {\tt GAMS} since release 22.5 of the \footlink{http://www.gams.com/}{\tt GAMS} modeling system.
180 The system is available for \footlink{http://download.gams.com/download}{download from GAMS}. Without buying a license it works as a demo with limited capabilities. Documentation for using \Bonmin\ in {\tt GAMS} is available
181 \latexhtml{ at
182 $$
183 \mbox{\tt http://www.gams.com/solvers/coin.pdf}
184 $$
185 }{\href{http://www.gams.com/solvers/coin.pdf}{here}.}
186
187
188 \subsectionH{From a C/C++ program}{sec:run_cpp}
189 \Bonmin\ can also be run from within a C/C++ program if the user codes
190 the functions to compute first- and second-order derivatives.
191 An example of such a program is available in the subdirectory {\tt CppExample} of
192 the {\tt examples} directory. For further explanations, please refer to this example and to the reference manual.