1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
|
// (C) Copyright International Business Machines Corporation 2007
// All Rights Reserved.
// This code is published under the Eclipse Public License.
//
// Authors :
// Pierre Bonami, International Business Machines Corporation
//
// Date : 04/12/2007
#ifndef BabSetupBase_H
#define BabSetupBase_H
#include <string>
#include <list>
#include "CglCutGenerator.hpp"
#include "CbcHeuristic.hpp"
#include "OsiChooseVariable.hpp"
#include "BonOsiTMINLPInterface.hpp"
#include "IpSmartPtr.hpp"
#include "BonTMINLP2OsiLP.hpp"
namespace Bonmin
{
/** A class to have all elements necessary to setup a branch-and-bound.*/
class BabSetupBase
{
public:
/** Type for cut generation method with its frequency and string identification. */
struct CuttingMethod
{
int frequency;
std::string id;
CglCutGenerator * cgl;
bool atSolution;
bool normal;
bool always;
CuttingMethod():
atSolution(false),
normal(true),
always(false)
{}
CuttingMethod(const CuttingMethod & other):
frequency(other.frequency),
id(other.id),
cgl(other.cgl),
atSolution(other.atSolution),
normal(other.normal),
always(other.always)
{}
};
/** Type for heuristic method with its string identification. */
struct HeuristicMethod
{
std::string id;
CbcHeuristic* heuristic;
HeuristicMethod()
{}
HeuristicMethod(const HeuristicMethod & other):
id(other.id),
heuristic(other.heuristic)
{}
};
typedef std::list<CuttingMethod> CuttingMethods;
typedef std::list<HeuristicMethod > HeuristicMethods;
/** Strategies for comparing the nodes on the heap. */
enum NodeComparison {
bestBound = 0 /** Best bound*/,
DFS /** Depth First Search*/,
BFS /** Best First Search */,
dynamic /** Dynamic strategy, see <a href="http://www.coin-or.org/Doxygen/Cbc/class_cbc_branch_dynamic_decision.html">
CbcBranchActual.hpp </a> for explanations.*/,
bestGuess /** Best guessed integer solution is subtree below, based on pseudo costs */
};
/** Strategies for traversing the tree.*/
enum TreeTraversal {
HeapOnly=0 /** Only using the heap, uses CbcTree.*/,
DiveFromBest /** dive from top node of the heap untill it gets to a leaf of the tree. Uses Bonmin::CbcDiver.*/,
ProbedDive /** Eplore two kids before following on dive.*/,
DfsDiveFromBest /** dive from top node of the heap with more elaborate strategy (see options doc). Uses Bonmin::CbcDfsDiver.*/,
DfsDiveDynamic /** Same as DfsDiveFromBest, but after a prescribed number of integer solution are found switch to best-bound and if too many node switches to depth-first. Uses Bonmin::CbcDfsDiver.*/
};
/** @name Enums for optionslist parameters */
enum VarSelectStra_Enum {
MOST_FRACTIONAL=0,
STRONG_BRANCHING,
RELIABILITY_BRANCHING,
#ifdef BONMIN_CURVATURE_BRANCHING
CURVATURE_ESTIMATOR,
#endif
QP_STRONG_BRANCHING,
LP_STRONG_BRANCHING,
NLP_STRONG_BRANCHING,
OSI_SIMPLE,
OSI_STRONG,
RANDOM
};
/** Parameters represented by an integer. */
enum IntParameter{
BabLogLevel = 0 /** Log level of main branch-and-bound*/,
BabLogInterval/** Display information every logIntervval nodes.*/,
MaxFailures /** Max number of failures in a branch.*/,
FailureBehavior /** Behavior of the algorithm in the case of a failure.*/,
MaxInfeasible /** Max number of consecutive infeasible problem in a branch
before fathoming.*/,
NumberStrong /** Number of candidates for strong branching.*/,
MinReliability /** Minimum reliability before trust pseudo-costs.*/,
MaxNodes /** Global node limit.*/,
MaxSolutions /** limit on number of integer feasible solution.*/,
MaxIterations /** Global iteration limit. */,
SpecialOption /** Spetial option in particular for Cbc. */,
DisableSos /** Consider or not SOS constraints.*/,
NumCutPasses/** Number of cut passes at nodes.*/,
NumCutPassesAtRoot/** Number of cut passes at nodes.*/,
RootLogLevel/** Log level for root relaxation.*/,
NumberIntParam /** Dummy end to size table*/
};
/** Parameters represented by a double.*/
enum DoubleParameter{
CutoffDecr = 0 /** Amount by which cutoff is incremented */,
Cutoff /** cutoff value */,
AllowableGap /** Stop if absolute gap is less than this. */,
AllowableFractionGap /** Stop if relative gap is less than this.*/,
IntTol /** Integer tolerance.*/,
MaxTime /** Global time limit. */,
NumberDoubleParam /** Dummy end to size table*/
};
/** Default constructor. */
BabSetupBase(const CoinMessageHandler * handler = NULL);
/** Construct from existing tminlp. */
BabSetupBase(Ipopt::SmartPtr<TMINLP> tminlp, const CoinMessageHandler * handler = NULL);
/** Construct from existing application.*/
BabSetupBase(Ipopt::SmartPtr<TNLPSolver> app);
/** Construct from existing TMINLP interface.*/
BabSetupBase(const OsiTMINLPInterface& nlp);
/** Copy but uses an other nlp.*/
BabSetupBase(const BabSetupBase &setup,
OsiTMINLPInterface &nlp);
/** Copy but uses an other nlp.*/
BabSetupBase(const BabSetupBase &setup,
OsiTMINLPInterface &nlp,
const std::string &prefix);
/** Copy constructor. */
BabSetupBase(const BabSetupBase & other);
/** virtual copy constructor. */
virtual BabSetupBase * clone() const = 0;
/** Make a copy with solver replace by one passed .*/
virtual BabSetupBase *clone(OsiTMINLPInterface&nlp)const;
/** Virtual destructor. */
virtual ~BabSetupBase();
/** @name Methods to initialize algorithm with various inputs. */
/** @{ */
/** use existing TMINLP interface (containing the options).*/
void use(const OsiTMINLPInterface& nlp);
/** Read options (if not done before) and create interface using tminlp.*/
void use(Ipopt::SmartPtr<TMINLP> tminlp );
/** use specific instanciation of a TMINLP2TNLP.*/
void use(Ipopt::SmartPtr<TMINLP2TNLP> prob);
/** Set the non-linear solver used */
void setNonlinearSolver(OsiTMINLPInterface * s)
{
nonlinearSolver_ = s;
}
/** @} */
/** @name Methods to manipulate options. */
/** @{ */
/** Register all the options for this algorithm instance.*/
virtual void registerOptions();
/** Setup the defaults options for this algorithm. */
virtual void setBabDefaultOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
{}
/** Register all the options for this algorithm instance.*/
static void registerAllOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
/** Get the options from default text file (bonmin.opt) if don't already have them.*/
virtual void readOptionsFile()
{
if (readOptions_) return;
readOptionsFile("bonmin.opt");
}
/** Get the options from given fileName */
void readOptionsFile(std::string fileName);
/** Get the options from long string containing all.*/
void readOptionsString(std::string opt_string);
/** Get the options from stream.*/
void readOptionsStream(std::istream& is);
/** May print documentation of options if options print_options_documentation is set to yes.*/
void mayPrintDoc();
/** Get prefix to use for options.*/
const char * prefix() const {
return prefix_.c_str();
}
/** Set the value for options, output...*/
void setOptionsAndJournalist(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
Ipopt::SmartPtr<Ipopt::OptionsList> options,
Ipopt::SmartPtr<Ipopt::Journalist> journalist)
{
options_ = options;
roptions_ = roptions;
journalist_ = journalist;
}
/** Initialize the options and the journalist.*/
void initializeOptionsAndJournalist();
/** @} */
/** @name Elements of the branch-and-bound setup.*/
/** @{ */
/** Pointer to the non-linear solver used.*/
OsiTMINLPInterface * nonlinearSolver()
{
return nonlinearSolver_;
}
/** Pointer to the continuous solver to use for relaxations. */
OsiSolverInterface * continuousSolver()
{
return continuousSolver_;
}
/** list of cutting planes methods to apply with their frequencies. */
CuttingMethods& cutGenerators()
{
return cutGenerators_;
}
/** list of Heuristic methods to use. */
HeuristicMethods& heuristics()
{
return heuristics_;
}
/** branching method to use. */
OsiChooseVariable * branchingMethod()
{
return branchingMethod_;
}
/** Method used to compare nodes. */
NodeComparison& nodeComparisonMethod()
{
return nodeComparisonMethod_;
}
/** Method used to traverse tree.*/
TreeTraversal treeTraversalMethod()
{
return treeTraversalMethod_;
}
/** Return value of integer parameter. */
int getIntParameter(const IntParameter &p) const
{
return intParam_[p];
}
/** Return value of double parameter.*/
double getDoubleParameter(const DoubleParameter &p) const
{
return doubleParam_[p];
}
/** Return value of integer parameter. */
void setIntParameter(const IntParameter &p, const int v)
{
intParam_[p] = v;
}
/** Return value of double parameter.*/
void setDoubleParameter(const DoubleParameter &p, const double v)
{
doubleParam_[p] = v;
}
/** @} */
/** Get the values of base parameters from the options stored.*/
void gatherParametersValues()
{
gatherParametersValues(options_);
}
/** Get the values of the base parameters from the passed options.*/
void gatherParametersValues(Ipopt::SmartPtr<Ipopt::OptionsList> options);
/** Acces storage of Journalist for output */
Ipopt::SmartPtr<Ipopt::Journalist> journalist()
{
return journalist_;
}
/** Acces list of Options */
Ipopt::SmartPtr<Ipopt::OptionsList> options()
{
return options_;
}
/** Access registered Options */
Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions()
{
return roptions_;
}
/** Access to extra objects.*/
const vector<OsiObject *>& objects() const
{
return objects_;
}
/** Access to extra objects.*/
vector<OsiObject *>& objects()
{
return objects_;
}
void addCutGenerator(CuttingMethod & cg){
cutGenerators_.push_back(cg);
}
void set_linearizer(TMINLP2OsiLP * linearizer){
linearizer_ = linearizer;
}
protected:
/** Set the priorities into OsiTMINLPInterface when needed.*/
void setPriorities();
/** Add SOS constraints to OsiTMINLPInterface when needed.*/
void addSos();
/** storage of integer parameters.*/
int intParam_[NumberIntParam];
/** default values for int parameters.*/
static int defaultIntParam_[NumberIntParam];
/** storage of double parameters. */
double doubleParam_[NumberDoubleParam];
/** default values for double parameters. */
static double defaultDoubleParam_[NumberDoubleParam];
/** Storage of the non-linear solver used.*/
OsiTMINLPInterface * nonlinearSolver_;
/** Storage of continuous solver.*/
OsiSolverInterface * continuousSolver_;
/** Method to linearize MINLPs */
Ipopt::SmartPtr<TMINLP2OsiLP> linearizer_;
/** Cut generation methods. */
CuttingMethods cutGenerators_;
/** Heuristic methods. */
HeuristicMethods heuristics_;
/** Branching method.*/
OsiChooseVariable * branchingMethod_;
/** Node comparison method.*/
NodeComparison nodeComparisonMethod_;
/** Tree traversal method.*/
TreeTraversal treeTraversalMethod_;
/** Extra object to add to Cbc (not OsiObjects).*/
vector<OsiObject *> objects_;
/** Storage of Journalist for output */
Ipopt::SmartPtr<Ipopt::Journalist> journalist_;
/** List of Options */
Ipopt::SmartPtr<Ipopt::OptionsList> options_;
/** Registered Options */
Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions_;
/** flag to say if option file was read.*/
bool readOptions_;
/** separate message handler.*/
CoinMessageHandler * messageHandler_;
/** Prefix to use when reading options.*/
std::string prefix_;
};
}/* End namespace Bonmin. */
#endif
|