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
14//y=log(x) and log constraint have same meaning
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) -cutmanager not implemented
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
107 struct LogCons
108 {
109 ConstraintPtr con;
112 VariablePtr riv;
113 VariablePtr rov;
114 char sense;
115 ConstraintPtr secCon;
116 ConstraintVector linCons;
117
118 LogCons(ConstraintPtr newcon, ConstVariablePtr ivar,
119 ConstVariablePtr ovar, char s)
120 : con(newcon),
121 iv(ivar),
122 ov(ovar),
123 riv(0),
124 rov(0),
125 sense(s),
126 secCon(0),
127 linCons()
128 {
129 }
130 };
131
132 typedef LogCons *LogConsPtr;
133 typedef std::vector<LogConsPtr> LogConsVec;
134 typedef LogConsVec::iterator LogConsIter;
135
136 // All log constraints data
137 LogConsVec consd_;
138
139 // For printing
140 static const std::string me_;
141
142 //Stats to store separation data
143 struct SepaStats {
144 int iters;
145 int tangentcuts;
146 int optcuts;
147 int optrem;
148 double time;
149 };
150
151 // Presolve statistics container
152 struct LogPresolveStats
153 {
154 UInt iters;
155 double time;
156 UInt conDel;
157 UInt vBnd;
158 UInt nMods;
159
160 LogPresolveStats()
161 : iters(0),
162 time(0.0),
163 conDel(0),
164 vBnd(0),
165 nMods(0)
166 {
167 }
168 };
169
170 struct BoundTighteningStats
171 {
172 int niters;
173 int nLP;
174 int dlb;
175 int dub;
176 double timeLP;
177 };
178
179 BoundTighteningStats bStats_;
180 LogPresolveStats pStats_;
181 SepaStats sStats_;
182 // Default bounds for presolve
183 double LBd_;
184 double UBd_;
185
186 double bTol_;
187
188 // Environment
189 EnvPtr env_;
190
191 //Problem pointer to the original problem
192 ProblemPtr orig_;
193
194 // Optional cuts
195 ConstraintVector optCuts_;
196
197
198 // Absolute feasibility tolerance
199 double aTol_;
200
201 // Relative feasibility tolerance
202 double rTol_;
203
204 // Tolerances for log constraints
205 double eTol_;
206
207 // Tolerance for when lower and upper bounds are considered equal
208 double vTol_;
209 // Problem pointer to the transformed problem
210 ProblemPtr p_;
211
212 // Logger
213 LoggerPtr log_;
214
215 // Temporary vectors for evaluations
216 DoubleVector tmpX_;
217 DoubleVector grad_;
218
219
220 //separating
221 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
222 RelaxationPtr rel, bool& ifcuts);
223
224
225 //add default bounds for x in y=log(x) if no finite bound was added by presolve
226 double addDefaultLogBounds_(VariablePtr x, BoundType lu);
227
232 void addLin_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
233 DoubleVector &grad, ModVector &mods, bool init);
234
235
240 void addSecant_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
241 ModVector &mods, bool init);
242
243 //Marks duplicate constraint if changed == True
244 void dupRows_(bool *changed);
245 //branching decision
246 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v,
247 double bvalue);
248
254 LinearFunctionPtr getLogSec_(VariablePtr x, VariablePtr y, double lb,
255 double ub, double &rhs);
256
257 //returns the violation for functon y=log(x) and takes input solution vector
258 double getViol_(const LogCons &cd, const DoubleVector &x) const;
259
260
261 // Check feasibility.
262 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
263 bool &should_prune, double &inf_meas);
264
265
266
267
272 void initRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
273 DoubleVector &grad);
274
275
276 // For a given y = log(x) constraint,
277 // derive bounds on y from bounds on x. Also derive bounds on x from bounds
278 // on y.
279 bool propLogBnds_(LogConsPtr lcd, bool *changed);
280
281 //Deletes duplicate row which was marked by dupRows
282 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
283 bool *changed);
284
285
286
295 void updateRelax_(LogCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
296 DoubleVector &grad, ModVector &mods);
297
299 int updatePBnds_(VariablePtr p, double newlb, double newub,
300 bool *changed);
301
302 int updatePBnds_(VariablePtr v, double newlb, double newub,
303 RelaxationPtr rel, bool mod_rel, bool *changed,
304 ModVector &p_mods, ModVector &r_mods);
305
306
307 bool varBndsFromCons_(bool *changed);
308
309
310 };
311
312} // namespace Minotaur
313
314#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:416
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool)
Return branches for branching.
Definition LogHandler.cpp:556
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:1072
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:275
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:357
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition LogHandler.cpp:517
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition LogHandler.cpp:1077
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol)
Initial presolve.
Definition LogHandler.cpp:1034
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition LogHandler.cpp:293
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:1061
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition LogHandler.cpp:466
void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar, ConstVariablePtr ovar, char sense='E')
Definition LogHandler.cpp:312
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 Jul 17 2026