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 public:
34 // Constructor
35 LogHandler(EnvPtr env, ProblemPtr problem);
36 LogHandler(EnvPtr env, ProblemPtr problem, ProblemPtr orig_);
37 // Destructor
39
47 ConstVariablePtr ovar, char sense = 'E');
48
49 // base class method—not used here
50 void addConstraint(ConstraintPtr) { assert(0); }
51
52
53 // Full relaxation (unused)
55
56 // Create initial relaxation at root and then updation
57 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf);
58
59 //Base Class method
60 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
61 bool &should_prune, double &inf_meas);
62
63 // Separation (cuts) — not implemented yet.
65 CutManager *cutman, SolutionPoolPtr s_pool,
66 ModVector &p_mods, ModVector &r_mods, bool *sol_found,
67 SeparationStatus *status);
68
69 // Full relaxation at a node (unused for LogHandler)
71
72 // Incremental relaxation at a node.
73 void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible);
74
75 // Branching candidates.
76 void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x,
77 ModVector &mods, BrVarCandSet &cands,
78 BrCandVector &gencands, bool &is_inf);
79
80 // Branch modification for a variable.
81 ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x,
83
84 // Generate branches.
85 Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel,
86 SolutionPoolPtr s_pool);
87
88 // Top-level presolve.
89 SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol);
90
91 // Node-level presolve.
93 ModVector &p_mods, ModVector &r_mods);
94
95 // Name of the handler.
96 std::string getName() const override;
97
98 // Stats
99 void writeStats(std::ostream &out) const override;
100
101
102
103
104 private:
105 // ---------------------------------------------------------
106 // Per-constraint data for log constraints (data only)
107 // ---------------------------------------------------------
108 struct LogCons
109 {
110 ConstraintPtr con;
113 VariablePtr riv;
114 VariablePtr rov;
115 char sense;
116 ConstraintPtr secCon;
117 ConstraintVector linCons;
118
119 LogCons(ConstraintPtr newcon, ConstVariablePtr ivar,
120 ConstVariablePtr ovar, char s)
121 : con(newcon),
122 iv(ivar),
123 ov(ovar),
124 riv(0),
125 rov(0),
126 sense(s),
127 secCon(0),
128 linCons()
129 {
130 }
131 };
132
133 typedef LogCons *LogConsPtr;
134 typedef std::vector<LogConsPtr> LogConsVec;
135 typedef LogConsVec::iterator LogConsIter;
136
137 // All log constraints data
138 LogConsVec consd_;
139
140 // For printing
141 static const std::string me_;
142
143 //Stats to store separation data
144 struct SepaStats {
145 int iters;
146 int tangentcuts;
147 int optcuts;
148 int optrem;
149 double time;
150 };
151
152
153 // ---------------------------------------------------------
154 // Presolve statistics containers
155 // ---------------------------------------------------------
156 struct LogPresolveStats
157 {
158 UInt iters;
159 double time;
160 UInt conDel;
161 UInt vBnd;
162 UInt nMods;
163
164 LogPresolveStats()
165 : iters(0),
166 time(0.0),
167 conDel(0),
168 vBnd(0),
169 nMods(0)
170 {
171 }
172 };
173
174 struct BoundTighteningStats
175 {
176 int niters;
177 int nLP;
178 int dlb;
179 int dub;
180 double timeLP;
181 };
182
183 BoundTighteningStats bStats_;
184 LogPresolveStats pStats_;
185 SepaStats sStats_;
186 // Default bounds for presolve
187 double LBd_;
188 double UBd_;
189
190 double bTol_;
191
192 // Environment
193 EnvPtr env_;
194
195 //Problem pointer to the original problem
196 ProblemPtr orig_;
197
198 // Optional cuts
199 ConstraintVector optCuts_;
200
201
202 // Absolute feasibility tolerance
203 double aTol_;
204
205 // Relative feasibility tolerance
206 double rTol_;
207
208 // Tolerances for log constraints
209 double eTol_;
210
211 // Tolerance for when lower and upper bounds are considered equal
212 double vTol_;
213 // Problem pointer to the transformed problem
214 ProblemPtr p_;
215
216 // Logger
217 LoggerPtr log_;
218
219 // Temporary vectors for evaluations
220 DoubleVector tmpX_;
221 DoubleVector grad_;
222
223
224 //separating
225 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
226 RelaxationPtr rel, bool& ifcuts);
227
228
229 //add default bounds for x in y=log(x) if no finite bound was added by presolve
230 double addDefaultLogBounds_(VariablePtr x, BoundType lu);
231
236 void addLin_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
237 DoubleVector &grad, ModVector &mods, bool init);
238
239
244 void addSecant_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
245 ModVector &mods, bool init);
246
258 //Marks duplicate constraint if changed == True
259 void dupRows_(bool *changed);
260 //branching decision
261 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v,
262 double bvalue);
263
269 LinearFunctionPtr getLogSec_(VariablePtr x, VariablePtr y, double lb,
270 double ub, double &rhs);
271
272 //returns the violation for functon y=log(x) and takes input solution vector
273 double getViol_(const LogCons &cd, const DoubleVector &x) const;
274
275
276 // Check feasibility.
277 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
278 bool &should_prune, double &inf_meas);
279
280
281
282
287 void initRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
288 DoubleVector &grad);
289
290
291 // For a given y = log(x) constraint,
292 // derive bounds on y from bounds on x. Also derive bounds on x from bounds
293 // on y.
294 bool propLogBnds_(LogConsPtr lcd, bool *changed);
295
296 //Deletes duplicate row which was marked by dupRows
297 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
298 bool *changed);
299
300
301
310 void updateRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
311 DoubleVector &grad, ModVector &mods);
312
314 int updatePBnds_(VariablePtr p, double newlb, double newub,
315 bool *changed);
316
317 int updatePBnds_(VariablePtr v, double newlb, double newub,
318 RelaxationPtr rel, bool mod_rel, bool *changed,
319 ModVector &p_mods, ModVector &r_mods);
320
321
322 bool varBndsFromCons_(bool *changed);
323
324
325 };
326
327} // namespace Minotaur
328
329#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
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:419
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool)
Return branches for branching.
Definition LogHandler.cpp:559
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition LogHandler.h:70
std::string getName() const override
Return the name of the handler.
Definition LogHandler.cpp:1062
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition LogHandler.h:54
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf)
Create root relaxation if doing incremental node relaxations.
Definition LogHandler.cpp:278
void addConstraint(ConstraintPtr)
Add constraint to be handled by this handler.
Definition LogHandler.h:50
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition LogHandler.cpp:360
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition LogHandler.cpp:520
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition LogHandler.cpp:1067
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol)
Initial presolve.
Definition LogHandler.cpp:1024
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition LogHandler.cpp:296
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:1051
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition LogHandler.cpp:469
void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar, ConstVariablePtr ovar, char sense='E')
Definition LogHandler.cpp:315
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
BoundType
Different types of variable-bounds.
Definition Types.h:131
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 Mar 20 2026