Minotaur 0.4.1
Docs for developers
DistParBranchAndBound.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 MINOTAURDISTPARBRANCHANDBOUND_H
14#define MINOTAURDISTPARBRANCHANDBOUND_H
15
16#include "Types.h"
17#include <sys/time.h>
18
19namespace Minotaur {
20
21 struct DistParBabOptions;
22 struct DistParBabStats;
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 DistParBabOptions* DistParBabOptionsPtr;
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
55 DistParBranchAndBound(EnvPtr env, ProblemPtr p, UInt proc_rank, UInt num_procs);
56
58 virtual ~DistParBranchAndBound();
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
176 void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[],
177 ParPCBProcessorPtr parPCBProcessor[],
178 UInt nThreads);
179 void solveMasterProc_(ParNodeIncRelaxerPtr parNodeRelaxer[],
180 ParPCBProcessorPtr parPCBProcessor[],
181 UInt nThreads);
182 void solveWorkerProc_(ParNodeIncRelaxerPtr parNodeRelaxer[],
183 ParPCBProcessorPtr parPCBProcessor[],
184 UInt nThreads);
185
187 void print2dvec(std::vector<std::vector<int> > output);
188
190 void print2dvec(std::vector<std::vector<double> > output);
191
200 std::vector<std::vector<double> > readSerialOutput(const char* inputFile);
201
203 double totalTime();
204
206 void writeStats(std::ostream & out);
207
209 void writeParStats(std::ostream & out,
210 ParPCBProcessorPtr parPCBProcessor[]);
211
214
216 double getWallTime() {
217 struct timeval time;
218 if (gettimeofday(&time,NULL)) {
219 // Handle error
220 return 0;
221 }
222 return (double)time.tv_sec + (double)time.tv_usec * .000001;
223 }
224
225 private:
227 EnvPtr env_;
228
230 LoggerPtr logger_;
231
233 static const std::string me_;
234
235 void getBoundChanges_(NodePtr node, std::vector<double>& bound_changes);
236
237 void updateProcsRunningStatus_(std::vector<int>& proc_running);
238 void checkUbUpdates_(const std::vector<int>& proc_running);
239 void checkLbUpdatesFromOtherProcs_(double& globalBestLB, std::vector<double>& proc_lb);
240 //void checkLbUpdatesFromOtherProcs_(double& globalBestLB, const std::vector<int>& proc_running);
241 void distributeNodes_();
242
243 void getStartingNode_(bool *shouldWait, bool *shouldRun, std::vector<double>& node_data);
244
246 NodeProcessorPtr nodePrcssr_;
247
249 NodeRelaxerPtr nodeRlxr_;
250
252 DistParBabOptionsPtr options_;
253
258 HeurVector preHeurs_;
259
261 ProblemPtr problem_;
262
264 SolutionPoolPtr solPool_;
265
270 DistParBabStats *stats_;
271
273 SolveStatus status_;
274
282 Timer *timer_;
283
286
288 int proc_rank_;
289
291 int num_procs_;
292
293 double best_tree_lb;
294
295
302 NodePtr processRoot_(bool *should_prune, bool *should_dive);
303
304 // Node to be received to start processing of the assigned sub-tree
305 NodePtr getStartingNode_(bool *shouldWait, bool *shouldRun);
306
316 void processRoot_(bool *should_prune, bool *should_dive,
317 ParNodeIncRelaxerPtr parNodeRlxr,
318 ParPCBProcessorPtr nodePrcssr, WarmStartPtr ws,
319 NodePtr &node);
320
321
322 void sendUbToOtherProcs_(double val, const std::vector<int>& proc_running);
323
325 bool shouldPrune_(NodePtr node);
326
334 bool shouldStopPar_(double wallStartTime, double treeLb);
335
343 void showStatus_(bool current_uncounted);
344
356 void showParStatus_(UInt current_uncounted, double treeLb,
357 double wallStartTime);
358 };
359
362 {
365
368
370 double timeUsed;
371
374 };
375
376
379 {
382
385
391
394
397
403
406
408 double timeLimit;
409 };
410
412}
413#endif
414
Declare important 'types' used in Minotaur.
Implement a generic parallel branch-and-bound algorithm on a multicore cpu.
Definition: DistParBranchAndBound.h:48
virtual ~DistParBranchAndBound()
Destroy.
Definition: DistParBranchAndBound.cpp:95
void parsolveOppor(ParNodeIncRelaxerPtr parNodeRelaxer[], ParPCBProcessorPtr parPCBProcessor[], UInt nThreads)
Start solving the Problem using parallel branch-and-bound in an opportunistic mode.
Definition: DistParBranchAndBound.cpp:1173
void addPreRootHeur(HeurPtr h)
Add a heuristic that will be called before root node.
Definition: DistParBranchAndBound.cpp:119
void setLogLevel(LogLevel level)
Set log level.
Definition: DistParBranchAndBound.cpp:379
void writeParStats(std::ostream &out, ParPCBProcessorPtr parPCBProcessor[])
Write statistics of parallel algorithm to the ostream out.
Definition: DistParBranchAndBound.cpp:2695
void setNodeRelaxer(NodeRelaxerPtr nr)
Set the NodeRelaxer for setting-up relaxations at each node.
Definition: DistParBranchAndBound.cpp:391
void print2dvec(std::vector< std::vector< int > > output)
Print a two-dimensional vector (customized).
Definition: DistParBranchAndBound.cpp:273
DistParBranchAndBound()
Default constructor.
Definition: DistParBranchAndBound.cpp:61
int strToInt(std::string str)
Convert a string to integer data type.
Definition: DistParBranchAndBound.cpp:500
double totalTime()
Return total time taken.
Definition: DistParBranchAndBound.cpp:2710
void setNodeProcessor(NodeProcessorPtr p)
Set the NodeProcessor that processes each node.
Definition: DistParBranchAndBound.cpp:385
NodeRelaxerPtr getNodeRelaxer()
Return a pointer to NodeRelaxer used in branch-and-bound.
Definition: DistParBranchAndBound.cpp:153
void writeStats()
Write statistics to the logger.
NodeProcessorPtr getNodeProcessor()
Return a pointer to NodeProcessor used in branch-and-bound.
Definition: DistParBranchAndBound.cpp:147
UInt numProcNodes()
Return number of nodes processed while solving.
Definition: DistParBranchAndBound.cpp:251
SolveStatus getStatus()
Return the final status.
Definition: DistParBranchAndBound.cpp:165
ParTreeManagerPtr getTreeManager()
Return a pointer to the tree manager. The client can then directly query the ParTreeManager for its s...
Definition: DistParBranchAndBound.cpp:171
void solve()
Start solving the Problem using branch-and-bound.
double getPerGap()
Return the percentage gap between the lower and upper bounds.
Definition: DistParBranchAndBound.cpp:125
double getUb()
Return the upper bound for the solution value from the search tree.
Definition: DistParBranchAndBound.cpp:177
double getLb()
Return the lower bound from the search tree.
Definition: DistParBranchAndBound.cpp:131
void shouldCreateRoot(bool b)
Switch to turn on/off root-node creation.
Definition: DistParBranchAndBound.cpp:397
double getWallTime()
Get wall clock time.
Definition: DistParBranchAndBound.h:216
std::vector< std::vector< double > > readSerialOutput(const char *inputFile)
Read output of branch-and-bound tree generated by a single thread.
Definition: DistParBranchAndBound.cpp:358
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: DistParBranchAndBound.cpp:183
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
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: DistParBranchAndBound.h:379
double timeLimit
Time limit in seconds for the branch-and-bound.
Definition: DistParBranchAndBound.h:408
UInt nodeLimit
Limit on number of nodes processed.
Definition: DistParBranchAndBound.h:396
UInt solLimit
Limit on number of nodes processed.
Definition: DistParBranchAndBound.h:405
double perGapLimit
Stop if the percent gap between lower and upper bounds of the objective function falls below this lev...
Definition: DistParBranchAndBound.h:402
double logInterval
Time in seconds between status updates of the progress.
Definition: DistParBranchAndBound.h:393
DistParBabOptions()
Default constructor.
Definition: DistParBranchAndBound.cpp:2729
bool createRoot
Should the root be created in branch-and-bound (yes), or the user calls branch-and-bound after creati...
Definition: DistParBranchAndBound.h:390
Statistics about the branch-and-bound.
Definition: DistParBranchAndBound.h:362
DistParBabStats()
Constructor. All data is initialized to zero.
Definition: DistParBranchAndBound.cpp:2719
UInt nodesProc
Number of nodes processed.
Definition: DistParBranchAndBound.h:367
double updateTime
Time of the last log display.
Definition: DistParBranchAndBound.h:373
double timeUsed
Total time used in branch-and-bound.
Definition: DistParBranchAndBound.h:370

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