Minotaur 0.4.1
Docs for developers
ParBranchAndBound.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 MINOTAURPARBRANCHANDBOUND_H
14#define MINOTAURPARBRANCHANDBOUND_H
15
16#include "Types.h"
17#include <sys/time.h>
18
19namespace Minotaur {
20
21 struct ParBabOptions;
22 struct ParBabStats;
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 ParBabOptions* ParBabOptionsPtr;
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 ~ParBranchAndBound();
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
125 std::vector<std::vector<double> > mapSerialOutput (
126 std::vector<std::vector<double> >serVec,
127 std::vector<std::vector<double> >parVec);
128
131
137 void setLogLevel(LogLevel level);
138
145
152
160 void shouldCreateRoot(bool b);
161
163 void solve();
164
166 int strToInt(std::string str);
167
175 void parsolve(ParNodeIncRelaxerPtr parNodeRelaxer[],
176 ParPCBProcessorPtr parPCBProcessor[],
177 UInt nThreads);
178
187 void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[],
188 ParPCBProcessorPtr parPCBProcessor[],
189 UInt nThreads);
190
198 void parsolveSync(ParNodeIncRelaxerPtr parNodeRelaxer[],
199 ParPCBProcessorPtr parPCBProcessor[],
200 UInt nThreads);
201
203 void print2dvec(std::vector<std::vector<int> > output);
204
206 void print2dvec(std::vector<std::vector<double> > output);
207
216 std::vector<std::vector<double> > readSerialOutput(const char* inputFile);
217
219 double totalTime();
220
222 void writeStats(std::ostream & out);
223
225 void writeParStats(std::ostream & out,
226 ParPCBProcessorPtr parPCBProcessor[]);
227
230
232 double getWallTime() {
233 struct timeval time;
234 if (gettimeofday(&time,NULL)) {
235 // Handle error
236 return 0;
237 }
238 return (double)time.tv_sec + (double)time.tv_usec * .000001;
239 }
240
241 private:
243 EnvPtr env_;
244
246 LoggerPtr logger_;
247
249 static const std::string me_;
250
252 NodeProcessorPtr nodePrcssr_;
253
255 NodeRelaxerPtr nodeRlxr_;
256
258 ParBabOptionsPtr options_;
259
264 HeurVector preHeurs_;
265
267 ProblemPtr problem_;
268
270 SolutionPoolPtr solPool_;
271
276 ParBabStats *stats_;
277
279 SolveStatus status_;
280
288 Timer *timer_;
289
292
299 NodePtr processRoot_(bool *should_prune, bool *should_dive);
300
310 void processRoot_(bool *should_prune, bool *should_dive,
311 ParNodeIncRelaxerPtr parNodeRlxr,
312 ParPCBProcessorPtr nodePrcssr, WarmStartPtr ws,
313 NodePtr &node);
314
315
317 bool shouldPrune_(NodePtr node);
318
323 bool shouldStop_();
324
332 bool shouldStopPar_(double wallStartTime, double treeLb);
333
341 void showStatus_(bool current_uncounted);
342
354 void showParStatus_(UInt current_uncounted, double treeLb,
355 double wallStartTime, UInt threadId);
356 };
357
360 {
362 ParBabStats();
363
366
368 double timeUsed;
369
372 };
373
374
377 {
380
383
389
392
395
401
404
406 double timeLimit;
407 };
408
410}
411#endif
412
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
Implement a generic parallel branch-and-bound algorithm on a multicore cpu.
Definition: ParBranchAndBound.h:48
void writeStats()
Write statistics to the logger.
int strToInt(std::string str)
Convert a string to integer data type.
Definition: ParBranchAndBound.cpp:561
void setNodeProcessor(NodeProcessorPtr p)
Set the NodeProcessor that processes each node.
Definition: ParBranchAndBound.cpp:363
virtual ~ParBranchAndBound()
Destroy.
Definition: ParBranchAndBound.cpp:83
double totalTime()
Return total time taken.
Definition: ParBranchAndBound.cpp:1903
ParTreeManagerPtr getTreeManager()
Return a pointer to the tree manager. The client can then directly query the ParTreeManager for its s...
Definition: ParBranchAndBound.cpp:149
void parsolve(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads)
Start solving the Problem using branch-and-bound.
Definition: ParBranchAndBound.cpp:1012
void parsolveSync(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads)
Branch-and-bound solver with reproducibility of results.
Definition: ParBranchAndBound.cpp:1493
std::vector< std::vector< double > > readSerialOutput(const char *inputFile)
Read output of branch-and-bound tree generated by a single thread.
Definition: ParBranchAndBound.cpp:336
void setLogLevel(LogLevel level)
Set log level.
Definition: ParBranchAndBound.cpp:357
void writeParStats(std::ostream &out, ParPCBProcessorPtr parPCBProcessor[])
Write statistics of parallel algorithm to the ostream out.
Definition: ParBranchAndBound.cpp:1888
double getWallTime()
Get wall clock time.
Definition: ParBranchAndBound.h:232
NodeRelaxerPtr getNodeRelaxer()
Return a pointer to NodeRelaxer used in branch-and-bound.
Definition: ParBranchAndBound.cpp:131
NodeProcessorPtr getNodeProcessor()
Return a pointer to NodeProcessor used in branch-and-bound.
Definition: ParBranchAndBound.cpp:125
SolveStatus getStatus()
Return the final status.
Definition: ParBranchAndBound.cpp:143
double getPerGap()
Return the percentage gap between the lower and upper bounds.
Definition: ParBranchAndBound.cpp:113
void print2dvec(std::vector< std::vector< int > > output)
Print a two-dimensional vector (customized).
Definition: ParBranchAndBound.cpp:251
void solve()
Start solving the Problem using branch-and-bound.
UInt numProcNodes()
Return number of nodes processed while solving.
Definition: ParBranchAndBound.cpp:229
void setNodeRelaxer(NodeRelaxerPtr nr)
Set the NodeRelaxer for setting-up relaxations at each node.
Definition: ParBranchAndBound.cpp:369
void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads)
Start solving the Problem using parallel branch-and-bound in an opportunistic mode.
Definition: ParBranchAndBound.cpp:587
void shouldCreateRoot(bool b)
Switch to turn on/off root-node creation.
Definition: ParBranchAndBound.cpp:375
std::vector< std::vector< double > > mapSerialOutput(std::vector< std::vector< double > >serVec, std::vector< std::vector< double > >parVec)
Map nodes generated in serial and parallel branch-and-bound tree.
Definition: ParBranchAndBound.cpp:161
double getUb()
Return the upper bound for the solution value from the search tree.
Definition: ParBranchAndBound.cpp:155
double getLb()
Return the lower bound from the search tree.
Definition: ParBranchAndBound.cpp:119
void addPreRootHeur(HeurPtr h)
Add a heuristic that will be called before root node.
Definition: ParBranchAndBound.cpp:107
ParBranchAndBound()
Default constructor.
Definition: ParBranchAndBound.cpp:52
Definition: ParNodeIncRelaxer.h:32
Default node processor used in solver for now.
Definition: ParPCBProcessor.h:47
Base class for managing the branch-and-bound tree.
Definition: ParTreeManager.h:29
Definition: Problem.h:74
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: ParBranchAndBound.h:377
UInt solLimit
Limit on number of nodes processed.
Definition: ParBranchAndBound.h:403
double logInterval
Time in seconds between status updates of the progress.
Definition: ParBranchAndBound.h:391
UInt nodeLimit
Limit on number of nodes processed.
Definition: ParBranchAndBound.h:394
double timeLimit
Time limit in seconds for the branch-and-bound.
Definition: ParBranchAndBound.h:406
ParBabOptions()
Default constructor.
Definition: ParBranchAndBound.cpp:1922
bool createRoot
Should the root be created in branch-and-bound (yes), or the user calls branch-and-bound after creati...
Definition: ParBranchAndBound.h:388
double perGapLimit
Stop if the percent gap between lower and upper bounds of the objective function falls below this lev...
Definition: ParBranchAndBound.h:400
Statistics about the branch-and-bound.
Definition: ParBranchAndBound.h:360
UInt nodesProc
Number of nodes processed.
Definition: ParBranchAndBound.h:365
ParBabStats()
Constructor. All data is initialized to zero.
Definition: ParBranchAndBound.cpp:1912
double updateTime
Time of the last log display.
Definition: ParBranchAndBound.h:371
double timeUsed
Total time used in branch-and-bound.
Definition: ParBranchAndBound.h:368

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025