Minotaur 0.4.1
Docs for developers
ParQGBranchAndBound.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2008 - 2025 The Minotaur Team.
5//
6
13#ifndef MINOTAURPARQGBRANCHANDBOUND_H
14#define MINOTAURPARQGBRANCHANDBOUND_H
15
16#include "Types.h"
17#include <sys/time.h>
18
19namespace Minotaur {
20
21 struct ParQGBabOptions;
22 struct ParQGBabStats;
23 class Engine;
24 class NodeProcessor;
25 class NodeRelaxer;
26 class ParNodeIncRelaxer;
27 class ParPCBProcessor;
28 class ParTreeManager;
29 class Problem;
30 class Solution;
31 class SolutionPool;
32 class WarmStart;
33 class Timer;
34 typedef Engine* EnginePtr;
35 typedef ParQGBabOptions* ParQGBabOptionsPtr;
36 typedef NodeProcessor* NodeProcessorPtr;
37 typedef NodeRelaxer* NodeRelaxerPtr;
38 typedef ParNodeIncRelaxer* ParNodeIncRelaxerPtr;
39 typedef ParPCBProcessor* ParPCBProcessorPtr;
40 typedef Solution* SolutionPtr;
41 typedef SolutionPool* SolutionPoolPtr;
42 typedef ParTreeManager* ParTreeManagerPtr;
43 typedef WarmStart* WarmStartPtr;
44
49
50 public:
53
56
58 virtual ~ParQGBranchAndBound();
59
60 void printsomething();
66 void addPreRootHeur(HeurPtr h);
67
76 double getPerGap();
77
84 double getLb();
85
88
91
92 /*
93 * \brief Return solution from the last solve. If no solution was found, return
94 * NULL.
95 */
96 SolutionPtr getSolution();
97
100
106
114 double getUb();
115
118
124 void setLogLevel(LogLevel level);
125
132
139
147 void shouldCreateRoot(bool b);
148
150 void solve();
151
160 void parsolve(ParNodeIncRelaxerPtr parNodeRelaxer[],
161 ParPCBProcessorPtr parPCBProcessor[],
162 UInt nThreads, bool prune);
163
172 void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[],
173 ParPCBProcessorPtr parPCBProcessor[],
174 UInt nThreads, bool prune);
175
183 void parsolveSync(ParNodeIncRelaxerPtr parNodeRelaxer[],
184 ParPCBProcessorPtr parPCBProcessor[],
185 UInt nThreads, bool prune);
186
193 void removeAddedCons(RelaxationPtr rel, UInt nc);
194
196 double totalTime();
197
199 void writeStats(std::ostream & out);
200
202 void writeParStats(std::ostream & out,
203 ParPCBProcessorPtr parPCBProcessor[]);
204
207
209 double getWallTime() {
210 struct timeval time;
211 if (gettimeofday(&time,NULL)) {
212 // Handle error
213 return 0;
214 }
215 return (double)time.tv_sec + (double)time.tv_usec * .000001;
216 }
217
218 private:
220 EnvPtr env_;
221
223 LoggerPtr logger_;
224
226 static const std::string me_;
227
229 NodeProcessorPtr nodePrcssr_;
230
232 NodeRelaxerPtr nodeRlxr_;
233
235 ParQGBabOptionsPtr options_;
236
241 HeurVector preHeurs_;
242
244 ProblemPtr problem_;
245
247 SolutionPoolPtr solPool_;
248
253 ParQGBabStats *stats_;
254
256 SolveStatus status_;
257
265 Timer *timer_;
266
269
276 NodePtr processRoot_(bool *should_prune, bool *should_dive);
277
287 NodePtr processRoot_(bool *should_prune, bool *should_dive,
288 ParNodeIncRelaxerPtr parNodeRlxr,
289 ParPCBProcessorPtr nodePrcssr, WarmStartPtr ws,
290 NodePtr &node);
291
293 bool shouldPrune_(NodePtr node);
294
299 bool shouldStop_();
300
308 bool shouldStopPar_(double wallStartTime, double treeLb);
309
317 void showStatus_(bool current_uncounted);
318
330 void showParStatus_(UInt current_uncounted, double treeLb,
331 double wallStartTime, UInt threadId);
332 };
333
336 {
339
342
344 double timeUsed;
345
348 };
349
350
353 {
356
359
365
368
371
374
380
383
385 double timeLimit;
386 };
387
389}
390#endif
391
Declare important 'types' used in Minotaur.
Definition: Environment.h:28
Definition: Heuristic.h:30
Definition: Logger.h:37
Definition: NodeProcessor.h:49
Definition: NodeRelaxer.h:42
Definition: Node.h:54
Definition: ParNodeIncRelaxer.h:32
Default node processor used in solver for now.
Definition: ParPCBProcessor.h:47
Implement a generic parallel branch-and-bound algorithm on a multicore cpu.
Definition: ParQGBranchAndBound.h:48
void setNodeProcessor(NodeProcessorPtr p)
Set the NodeProcessor that processes each node.
Definition: ParQGBranchAndBound.cpp:247
NodeProcessorPtr getNodeProcessor()
Return a pointer to NodeProcessor used in branch-and-bound.
Definition: ParQGBranchAndBound.cpp:130
double getUb()
Return the upper bound for the solution value from the search tree.
Definition: ParQGBranchAndBound.cpp:160
ParTreeManagerPtr getTreeManager()
Return a pointer to the tree manager. The client can then directly query the ParTreeManager for its s...
Definition: ParQGBranchAndBound.cpp:154
void shouldCreateRoot(bool b)
Switch to turn on/off root-node creation.
Definition: ParQGBranchAndBound.cpp:259
void solve()
Start solving the Problem using branch-and-bound.
double getLb()
Return the lower bound from the search tree.
Definition: ParQGBranchAndBound.cpp:124
UInt numProcNodes()
Return number of nodes processed while solving.
Definition: ParQGBranchAndBound.cpp:166
double totalTime()
Return total time taken.
Definition: ParQGBranchAndBound.cpp:1796
void parsolve(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads, bool prune)
Start solving the Problem using branch-and-bound.
Definition: ParQGBranchAndBound.cpp:885
void addPreRootHeur(HeurPtr h)
Add a heuristic that will be called before root node.
Definition: ParQGBranchAndBound.cpp:112
void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads, bool prune)
Start solving the Problem using parallel branch-and-bound in an opportunistic mode.
Definition: ParQGBranchAndBound.cpp:418
void removeAddedCons(RelaxationPtr rel, UInt nc)
Function to remove the constraints added to this relaxation.
Definition: ParQGBranchAndBound.cpp:410
double getWallTime()
Get wall clock time.
Definition: ParQGBranchAndBound.h:209
virtual ~ParQGBranchAndBound()
Destroy.
Definition: ParQGBranchAndBound.cpp:88
SolveStatus getStatus()
Return the final status.
Definition: ParQGBranchAndBound.cpp:148
NodeRelaxerPtr getNodeRelaxer()
Return a pointer to NodeRelaxer used in branch-and-bound.
Definition: ParQGBranchAndBound.cpp:136
ParQGBranchAndBound()
Default constructor.
Definition: ParQGBranchAndBound.cpp:57
void setLogLevel(LogLevel level)
Set log level.
Definition: ParQGBranchAndBound.cpp:241
void writeStats()
Write statistics to the logger.
double getPerGap()
Return the percentage gap between the lower and upper bounds.
Definition: ParQGBranchAndBound.cpp:118
void writeParStats(std::ostream &out, ParPCBProcessorPtr parPCBProcessor[])
Write statistics of parallel algorithm to the ostream out.
Definition: ParQGBranchAndBound.cpp:1781
void parsolveSync(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads, bool prune)
Branch-and-bound solver with reproducibility of results.
Definition: ParQGBranchAndBound.cpp:1377
void setNodeRelaxer(NodeRelaxerPtr nr)
Set the NodeRelaxer for setting-up relaxations at each node.
Definition: ParQGBranchAndBound.cpp:253
Base class for managing the branch-and-bound tree.
Definition: ParTreeManager.h:29
Definition: Problem.h:74
Definition: Relaxation.h:53
Definition: SolutionPool.h:28
Definition: Solution.h:30
Definition: Timer.h:40
Definition: WarmStart.h:45
Definition: ActiveNodeStore.h:20
LogLevel
Levels of verbosity.
Definition: Types.h:226
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition: Types.h:158
Different options and parameters that control branch-and-bound.
Definition: ParQGBranchAndBound.h:353
double perGapLimit
Stop if the percent gap between lower and upper bounds of the objective function falls below this lev...
Definition: ParQGBranchAndBound.h:379
ParQGBabOptions()
Default constructor.
Definition: ParQGBranchAndBound.cpp:1815
bool createRoot
Should the root be created in branch-and-bound (yes), or the user calls branch-and-bound after creati...
Definition: ParQGBranchAndBound.h:364
double logInterval
Time in seconds between status updates of the progress.
Definition: ParQGBranchAndBound.h:367
UInt solLimit
Limit on number of nodes processed.
Definition: ParQGBranchAndBound.h:382
UInt nodeLimit
Limit on number of nodes processed.
Definition: ParQGBranchAndBound.h:373
LogLevel logLevel
Verbosity of log.
Definition: ParQGBranchAndBound.h:370
double timeLimit
Time limit in seconds for the branch-and-bound.
Definition: ParQGBranchAndBound.h:385
Statistics about the branch-and-bound.
Definition: ParQGBranchAndBound.h:336
double timeUsed
Total time used in branch-and-bound.
Definition: ParQGBranchAndBound.h:344
ParQGBabStats()
Constructor. All data is initialized to zero.
Definition: ParQGBranchAndBound.cpp:1805
UInt nodesProc
Number of nodes processed.
Definition: ParQGBranchAndBound.h:341
double updateTime
Time of the last log display.
Definition: ParQGBranchAndBound.h:347

Minotaur source code documented by Doxygen 1.9.4 on Sat May 17 2025