Minotaur 0.4.1
Docs for developers
BranchAndBound.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
14#ifndef MINOTAURBRANCHANDBOUND_H
15#define MINOTAURBRANCHANDBOUND_H
16
17#include "Types.h"
18#include "Environment.h"
19#include "Brancher.h"
20#include "Heuristic.h"
21#include "NodeProcessor.h"
22#include "NodeRelaxer.h"
23#include "Problem.h"
24#include "Relaxation.h"
25#include "SolutionPool.h"
26#include "TreeManager.h"
27
28namespace Minotaur {
29
30 struct BabOptions;
31 struct BabStats;
32 typedef BabOptions* BabOptionsPtr;
33
34
39
40 public:
43
45 BranchAndBound(EnvPtr env, ProblemPtr problem);
46
48 virtual ~BranchAndBound();
49
55 void addPreRootHeur(HeurPtr h);
56
65 double getPerGap();
66
73 double getLb();
74
77
80
81 /*
82 * \brief Return solution from the last solve. If no solution was found, return
83 * NULL.
84 */
85 SolutionPtr getSolution();
86
87 /*
88 * \brief Return solution from the root node solve. If no solution was found, return
89 * NULL.
90 */
91 //SolutionPtr getRootSolution();
92
95
101
109 double getUb();
110
113
119 void setLogLevel(LogLevel level);
120
127
134
142 void shouldCreateRoot(bool b);
143
145 void solve();
146
148 double totalTime();
149
151 void writeStats(std::ostream & out);
152
155
156 private:
158 EnvPtr env_;
159
161 LoggerPtr logger_;
162
164 static const std::string me_;
165
167 NodeProcessorPtr nodePrcssr_;
168
170 NodeRelaxerPtr nodeRlxr_;
171
173 BabOptionsPtr options_;
174
179 HeurVector preHeurs_;
180
182 ProblemPtr problem_;
183
185 SolutionPoolPtr solPool_;
186
191 BabStats *stats_;
192
194 SolveStatus status_;
195
203 const Timer *timer_;
204
206 TreeManagerPtr tm_;
207
214 NodePtr processRoot_(bool *should_prune, bool *should_dive);
215
217 bool shouldPrune_(NodePtr node);
218
223 bool shouldStop_();
224
232 void showStatus_(bool current_uncounted,bool last_line);
233
234 void showStatusHead_();
235 };
236
238 struct BabStats
239 {
241 BabStats();
242
245
247 double timeUsed;
248
251 };
252
253
256 {
258 BabOptions();
259
261 BabOptions(EnvPtr env);
262
268
271
274
280
283
285 double timeLimit;
286 };
287
289}
290#endif
291
Declare the base class Brancher for finding and creating branches in Branch-and-Bound.
Define the Environment class.
Define abstract base class for heuristics of various kinds.
Define the NodeProcessor class for processing nodes in the branch-and-bound algorithm.
Define the NodeRelaxer class for creating relaxation for nodes in the branch-and-bound algorithm.
Declare the base class Modification.
Declare the class Relaxation for storing and manipulating relaxations.
Declare a container for storing solutions and their qualities.
Declare class ParTreeManager for managing tree for parallel Branch-and-Bound.
Declare important 'types' used in Minotaur.
Implement a generic branch-and-bound algorithm on a single cpu.
Definition: BranchAndBound.h:38
NodeRelaxerPtr getNodeRelaxer()
Return a pointer to NodeRelaxer used in branch-and-bound.
Definition: BranchAndBound.cpp:98
NodeProcessorPtr getNodeProcessor()
Return a pointer to NodeProcessor used in branch-and-bound.
Definition: BranchAndBound.cpp:93
void setNodeRelaxer(NodeRelaxerPtr nr)
Set the NodeRelaxer for setting-up relaxations at each node.
Definition: BranchAndBound.cpp:213
UInt numProcNodes()
Return number of nodes processed while solving.
Definition: BranchAndBound.cpp:128
void solve()
Start solving the Problem using branch-and-bound.
Definition: BranchAndBound.cpp:336
double getPerGap()
Return the percentage gap between the lower and upper bounds.
Definition: BranchAndBound.cpp:83
void setNodeProcessor(NodeProcessorPtr p)
Set the NodeProcessor that processes each node.
Definition: BranchAndBound.cpp:208
void shouldCreateRoot(bool b)
Switch to turn on/off root-node creation.
Definition: BranchAndBound.cpp:218
double getLb()
Return the lower bound from the search tree.
Definition: BranchAndBound.cpp:88
BranchAndBound()
Default constructor.
Definition: BranchAndBound.cpp:25
virtual ~BranchAndBound()
Destroy.
Definition: BranchAndBound.cpp:53
TreeManagerPtr getTreeManager()
Return a pointer to the tree manager. The client can then directly query the TreeManager for its size...
Definition: BranchAndBound.cpp:118
void writeStats()
Write statistics to the logger.
void addPreRootHeur(HeurPtr h)
Add a heuristic that will be called before root node.
Definition: BranchAndBound.cpp:78
double totalTime()
Return total time taken.
Definition: BranchAndBound.cpp:532
SolveStatus getStatus()
Return the final status.
Definition: BranchAndBound.cpp:113
void setLogLevel(LogLevel level)
Set log level.
Definition: BranchAndBound.cpp:203
double getUb()
Return the upper bound for the solution value from the search tree.
Definition: BranchAndBound.cpp:123
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: Problem.h:74
Definition: SolutionPool.h:28
Definition: Solution.h:30
Definition: Timer.h:40
Base class for managing the branch-and-bound tree.
Definition: TreeManager.h:29
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: BranchAndBound.h:256
double timeLimit
Time limit in seconds for the branch-and-bound.
Definition: BranchAndBound.h:285
UInt nodeLimit
Limit on number of nodes processed.
Definition: BranchAndBound.h:273
double logInterval
Time in seconds between status updates of the progress.
Definition: BranchAndBound.h:270
UInt solLimit
Limit on number of nodes processed.
Definition: BranchAndBound.h:282
double perGapLimit
Stop if the percent gap between lower and upper bounds of the objective function falls below this lev...
Definition: BranchAndBound.h:279
BabOptions()
Default constructor.
Definition: BranchAndBound.cpp:548
bool createRoot
Should the root be created in branch-and-bound (yes), or the user calls branch-and-bound after creati...
Definition: BranchAndBound.h:267
Statistics about the branch-and-bound.
Definition: BranchAndBound.h:239
BabStats()
Constructor. All data is initialized to zero.
Definition: BranchAndBound.cpp:540
UInt nodesProc
Number of nodes processed.
Definition: BranchAndBound.h:244
double timeUsed
Total time used in branch-and-bound.
Definition: BranchAndBound.h:247
double updateTime
Time of the last log display.
Definition: BranchAndBound.h:250

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