Minotaur 0.4.1
Docs for developers
Loading...
Searching...
No Matches
LogHandler.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2010 - 2025 The Minotaur Team.
5//
6
15#ifndef MINOTAURLOGHANDLER_H
16#define MINOTAURLOGHANDLER_H
17
18#include "Handler.h"
19#include "Types.h"
20namespace Minotaur {
21
22 class Engine;
23 class Function;
24 class LinearFunction;
25 class Objective;
26 class Problem;
27 typedef LinearFunction *LinearFunctionPtr;
28 typedef Objective *ObjectivePtr;
29
30
31 class LogHandler : public Handler {
32
33
34 private:
35 // ---------------------------------------------------------
36 // Per-constraint data for log constraints (data only)
37 // ---------------------------------------------------------
38 struct LogCons
39 {
40 ConstraintPtr con;
43 VariablePtr riv;
44 VariablePtr rov;
45 char sense;
46 ConstraintPtr secCon;
47 ConstraintVector linCons;
48
49 LogCons(ConstraintPtr newcon, ConstVariablePtr ivar,
50 ConstVariablePtr ovar, char s)
51 : con(newcon),
52 iv(ivar),
53 ov(ovar),
54 riv(0),
55 rov(0),
56 sense(s),
57 secCon(0),
58 linCons()
59 {
60 }
61 };
62
63 typedef LogCons *LogConsPtr;
64 typedef std::vector<LogConsPtr> LogConsVec;
65 typedef LogConsVec::iterator LogConsIter;
66
67 // All log constraints data
68 LogConsVec consd_;
69
70 // For printing
71 static const std::string me_;
72
73 // ---------------------------------------------------------
74 // Presolve statistics containers
75 // ---------------------------------------------------------
76 struct LogPresolveStats
77 {
78 UInt iters;
79 double time;
80 UInt conDel;
81 UInt vBnd;
82 UInt nMods;
83
84 LogPresolveStats()
85 : iters(0),
86 time(0.0),
87 conDel(0),
88 vBnd(0),
89 nMods(0)
90 {
91 }
92 };
93
94 struct BoundTighteningStats
95 {
96 int niters;
97 int nLP;
98 int dlb;
99 int dub;
100 double timeLP;
101 };
102
103 BoundTighteningStats bStats_;
104 LogPresolveStats pStats_;
105
106 // Default bounds for presolve
107 double LBd_;
108 double UBd_;
109 double bTol_;
110
111 // Environment
112 EnvPtr env_;
113
114 // Original problem
115 ProblemPtr orig_;
116
117 // Optional cuts
118 ConstraintVector optCuts_;
119
120
125 void addLin_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
126 DoubleVector &grad, ModVector &mods, bool init);
127
128
133 void addSecant_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
134 ModVector &mods, bool init);
135
147 //Marks duplicate constraint if changed == True
148 void dupRows_(bool *changed);
149 //branching decision
150 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v,
151 double bvalue);
152
153
154 double getViol_(const LogCons &cd, const DoubleVector &x) const;
155
160 void initRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
161 DoubleVector &grad);
162
163
164 // For a given y = log(x) constraint,
165 // derive bounds on y from bounds on x. Also derive bounds on x from bounds
166 // on y.
167 bool propLogBnds_(LogConsPtr lcd, bool *changed);
168
169 //Deletes duplicate row which was marked by dupRows
170 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
171 bool *changed);
172
173
174
183 void updateRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
184 DoubleVector &grad, ModVector &mods);
185
187 int updatePBnds_(VariablePtr p, double newlb, double newub,
188 bool *changed);
189
190 bool varBndsFromCons_(bool *changed);
191
192
193 // Absolute feasibility tolerance
194 double aTol_;
195
196 // Relative feasibility tolerance
197 double rTol_;
198
199 // Tolerances for log constraints
200 double eTol_;
201
202 // Tolerance for when lower and upper bounds are considered equal
203 double vTol_;
204
205 // Problem pointer
206 ProblemPtr p_;
207
208 // Logger
209 LoggerPtr log_;
210
211 // Temporary vectors for evaluations
212 DoubleVector tmpX_;
213 DoubleVector grad_;
214
215 public:
216 // Constructor
217 LogHandler(EnvPtr env, ProblemPtr problem);
218
219 // Destructor
220 ~LogHandler();
221
229 ConstVariablePtr ovar, char sense = 'E');
230
231 // base class method—not used here
232 void addConstraint(ConstraintPtr) { assert(0); }
233
234
235 // Full relaxation (unused)
237
238 // Create initial incremental relaxation.
239 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf);
240
241 // Check feasibility.
242 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
243 bool &should_prune, double &inf_meas);
244
245 // Separation (cuts) — not implemented yet.
247 CutManager *cutman, SolutionPoolPtr s_pool,
248 ModVector &p_mods, ModVector &r_mods, bool *sol_found,
249 SeparationStatus *status);
250
251 // Full relaxation at a node (unused for LogHandler)
253
254 // Incremental relaxation at a node.
255 void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible);
256
257 // Branching candidates.
258 void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x,
259 ModVector &mods, BrVarCandSet &cands,
260 BrCandVector &gencands, bool &is_inf);
261
262 // Branch modification for a variable.
263 ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x,
265
266 // Generate branches.
267 Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel,
268 SolutionPoolPtr s_pool);
269
270 // Top-level presolve.
271 SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol);
272
273 // Node-level presolve.
275 ModVector &p_mods, ModVector &r_mods);
276
277 // Name of the handler.
278 std::string getName() const override;
279
280 // Stats
281 void writeStats(std::ostream &out) const override;
282 };
283
284} // namespace Minotaur
285
286#endif // MINOTAURLOGHANDLER_H
Define abstract base class for handlers of various kinds.
Declare important 'types' used in Minotaur.
Base class for describing candidates for branching on a node in branch-and-bound.
Definition BrCand.h:32
Base class for storing branching modifications.
Definition Branch.h:33
The Constraint class is used to manage a constraint.
Definition Constraint.h:61
Abstract base class to manage cuts in the relaxation.
Definition CutManager.h:42
Definition Environment.h:28
Base class for handling specific types of constraints or objective.
Definition Handler.h:49
Definition LogHandler.h:31
void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel, CutManager *cutman, SolutionPoolPtr s_pool, ModVector &p_mods, ModVector &r_mods, bool *sol_found, SeparationStatus *status)
add cuts to separate a given point.
Definition LogHandler.cpp:369
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool)
Return branches for branching.
Definition LogHandler.cpp:456
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition LogHandler.h:252
std::string getName() const override
Return the name of the handler.
Definition LogHandler.cpp:815
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition LogHandler.h:236
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf)
Create root relaxation if doing incremental node relaxations.
Definition LogHandler.cpp:294
void addConstraint(ConstraintPtr)
Add constraint to be handled by this handler.
Definition LogHandler.h:232
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition LogHandler.cpp:346
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition LogHandler.cpp:419
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition LogHandler.cpp:820
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol)
Initial presolve.
Definition LogHandler.cpp:775
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition LogHandler.cpp:312
bool presolveNode(RelaxationPtr p, NodePtr node, SolutionPoolPtr s_pool, ModVector &p_mods, ModVector &r_mods)
Presolve the problem and its relaxation at a node.
Definition LogHandler.cpp:802
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition LogHandler.cpp:382
void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar, ConstVariablePtr ovar, char sense='E')
Definition LogHandler.cpp:332
Definition Logger.h:37
Definition Modification.h:29
Definition Node.h:54
Definition Problem.h:74
Definition Relaxation.h:53
Definition SolutionPool.h:28
Definition Solution.h:30
Definition Variable.h:31
Definition ActiveNodeStore.h:20
BranchDirection
Two directions for branching.
Definition Types.h:201
unsigned int UInt
Unsigned integer.
Definition Types.h:30
SeparationStatus
Status from separation routine:
Definition Types.h:217
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition Types.h:158

Minotaur source code documented by Doxygen 1.9.8 on Fri Jan 9 2026