Minotaur 0.4.1
Docs for developers
Loading...
Searching...
No Matches
ExpHandler.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=e^x and exp constraints have same meaning
15#ifndef MINOTAUREXPHANDLER_H
16#define MINOTAUREXPHANDLER_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 ExpHandler : public Handler {
32
33 public:
34 // Constructor
35 ExpHandler(EnvPtr env, ProblemPtr problem);
36 ExpHandler(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 ExpHandler)
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 // Per-constraint data for exponential constraints
106 struct ExpCons
107 {
108 ConstraintPtr con;
111 VariablePtr riv;
112 VariablePtr rov;
113 char sense;
114 ConstraintPtr secCon;
115 ConstraintVector linCons;
116
117 ExpCons(ConstraintPtr newcon, ConstVariablePtr ivar,
118 ConstVariablePtr ovar, char s)
119 : con(newcon),
120 iv(ivar),
121 ov(ovar),
122 riv(0),
123 rov(0),
124 sense(s),
125 secCon(0),
126 linCons()
127 {
128 }
129 };
130
131 typedef ExpCons *ExpConsPtr;
132 typedef std::vector<ExpConsPtr> ExpConsVec;
133 typedef ExpConsVec::iterator ExpConsIter;
134
135 // All exp constraints data
136 ExpConsVec consd_;
137
138 // For printing
139 static const std::string me_;
140
141 //Stats to store separation data
142 struct SepaStats {
143 int iters;
144 int tangentcuts;
145 int optcuts;
146 int optrem;
147 double time;
148 };
149
150
151 // ---------------------------------------------------------
152 // Presolve statistics containers
153 // ---------------------------------------------------------
154 struct ExpPresolveStats
155 {
156 UInt iters;
157 double time;
158 UInt conDel;
159 UInt vBnd;
160 UInt nMods;
161
162 ExpPresolveStats()
163 : iters(0),
164 time(0.0),
165 conDel(0),
166 vBnd(0),
167 nMods(0)
168 {
169 }
170 };
171
172 struct BoundTighteningStats
173 {
174 int niters;
175 int nLP;
176 int dlb;
177 int dub;
178 double timeLP;
179 };
180
181 BoundTighteningStats bStats_;
182 ExpPresolveStats pStats_;
183 SepaStats sStats_;
184 // Default bounds for presolve
185 double LBd_;
186 double UBd_;
187
188 double bTol_;
189
190 // Environment
191 EnvPtr env_;
192
193 //Problem pointer to the original problem
194 ProblemPtr orig_;
195
196 // Optional cuts
197 ConstraintVector optCuts_;
198
199
200 // Absolute feasibility tolerance
201 double aTol_;
202
203 // Relative feasibility tolerance
204 double rTol_;
205
206 // Tolerances for exp constraints
207 double eTol_;
208
209 // Tolerance for when lower and upper bounds are considered equal
210 double vTol_;
211 // Problem pointer to the transformed problem
212 ProblemPtr p_;
213
214 // Expger
215 LoggerPtr log_;
216
217 // Temporary vectors for evaluations
218 DoubleVector tmpX_;
219 DoubleVector grad_;
220
221
222 //separating
223 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
224 RelaxationPtr rel, bool& ifcuts);
225
226
227 //add default bounds for x in y=e^x if no finite bound was added by presolve
228 double addDefaultExpBounds_(VariablePtr x, BoundType lu);
229
234 void addLin_(ExpCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
235 DoubleVector &grad, ModVector &mods, bool init);
236
237
242 void addSecant_(ExpCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
243 ModVector &mods, bool init);
244
245
246 //Marks duplicate constraint if changed == True
247 void dupRows_(bool *changed);
248 //branching decision
249 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v,
250 double bvalue);
251
257 LinearFunctionPtr getExpSec_(VariablePtr x, VariablePtr y, double lb,
258 double ub, double &rhs);
259
260 //returns the violation for functon y=e^x and takes input solution vector
261 double getViol_(const ExpCons &cd, const DoubleVector &x) const;
262
263
264 // Check feasibility.
265 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
266 bool &should_prune, double &inf_meas);
267
268
269
270
275 void initRelax_(ExpCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
276 DoubleVector &grad);
277
278
279 // For a given y = e^x constraint,
280 // derive bounds on y from bounds on x. Also derive bounds on x from bounds
281 // on y.
282 bool propExpBnds_(ExpConsPtr lcd, bool *changed);
283
284 //Deletes duplicate row which was marked by dupRows
285 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
286 bool *changed);
287
288
289
298 void updateRelax_(ExpCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
299 DoubleVector &grad, ModVector &mods);
300
302 int updatePBnds_(VariablePtr p, double newlb, double newub,
303 bool *changed);
304
305 int updatePBnds_(VariablePtr v, double newlb, double newub,
306 RelaxationPtr rel, bool mod_rel, bool *changed,
307 ModVector &p_mods, ModVector &r_mods);
308
309
310 bool varBndsFromCons_(bool *changed);
311
312
313 };
314
315} // namespace Minotaur
316#endif // MINOTAUREXPHANDLER_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
Definition ExpHandler.h:31
std::string getName() const override
Return the name of the handler.
Definition ExpHandler.cpp:1040
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf)
Create root relaxation if doing incremental node relaxations.
Definition ExpHandler.cpp:268
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition ExpHandler.cpp:286
void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar, ConstVariablePtr ovar, char sense='E')
Definition ExpHandler.cpp:305
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition ExpHandler.h:70
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 ExpHandler.cpp:1029
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition ExpHandler.cpp:510
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition ExpHandler.h:54
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition ExpHandler.cpp:350
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition ExpHandler.cpp:459
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool)
Return branches for branching.
Definition ExpHandler.cpp:549
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol)
Initial presolve.
Definition ExpHandler.cpp:1002
void addConstraint(ConstraintPtr)
Add constraint to be handled by this handler.
Definition ExpHandler.h:50
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 ExpHandler.cpp:409
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition ExpHandler.cpp:1045
Base class for handling specific types of constraints or objective.
Definition Handler.h:49
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