Minotaur 0.4.1
Docs for developers
Loading...
Searching...
No Matches
PowHandler.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#ifndef MINOTAURPOWHANDLER_H
15#define MINOTAURPOWHANDLER_H
16
17#include "Handler.h"
18#include "Types.h"
19
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 class PowHandler : public Handler {
31 public:
32 // Constructor
33 PowHandler(EnvPtr env, ProblemPtr problem);
34 PowHandler(EnvPtr env, ProblemPtr problem, ProblemPtr orig_);
35
36 // Destructor
38
39 void addConstraint(ConstraintPtr newcon, ConstVariablePtr ivar,
40 ConstVariablePtr ovar, double degree, char sense = 'E');
41 //base method
42 void addConstraint(ConstraintPtr) { assert(0); }
43
44 //Does nothing
46 //Does Nothing
47 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf);
48 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
49 bool &should_prune, double &inf_meas);
50 //Checks if Cutting plane can be added or not based on convexity/concavity
52 CutManager *cutman, SolutionPoolPtr s_pool,
53 ModVector &p_mods, ModVector &r_mods, bool *sol_found,
54 SeparationStatus *status);
55
57
58 //Update the relaxation at each node
59 void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible);
60
61 void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x,
62 ModVector &mods, BrVarCandSet &cands,
63 BrCandVector &gencands, bool &is_inf);
64
65 ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x,
67
68 Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel,
69 SolutionPoolPtr s_pool);
70
71 SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol);
72
74 ModVector &p_mods, ModVector &r_mods);
75
76 std::string getName() const override;
77 void writeStats(std::ostream &out) const override;
78
79 private:
80
81 //
82 enum PowCurvature { PC_CONVEX, PC_CONCAVE, PC_MIXED };
83
84 enum PowType {
85 POS_OO,
86 POS_OE,
87 POS_EO,
88 NEG_OO,
89 NEG_OE,
90 NEG_EO,
91 };
94static const size_t POW_NUM_PT_SLOTS = 3;
95
97static const size_t POW_NUM_TAN_SLOTS = 3;
98 struct PowCons {
99 ConstraintPtr con;
100 ConstVariablePtr iv;
101 ConstVariablePtr ov;
102 double k;
103 int p;
104 int q;
105 PowType type;
106 VariablePtr riv;
107 VariablePtr rov;
108 char sense;
109 std::vector<ConstraintPtr> ptCons; // cuts through two points, by slot
110 std::vector<ConstraintPtr> tanCons; // cuts tangent at a point, by slot
111 PowCons(ConstraintPtr newcon, ConstVariablePtr ivar,
112 ConstVariablePtr ovar, double degree, int num, int den, PowType t, char s)
113 : con(newcon), iv(ivar), ov(ovar), k(degree), p(num), q(den) , type(t) ,riv(0), rov(0),
114 sense(s) {}
115 };
116 PowCurvature getCurvature_(const PowCons &cd, double xlb, double xub) const;
117
118 typedef PowCons *PowConsPtr;
119 typedef std::vector<PowConsPtr> PowConsVec;
120 typedef PowConsVec::iterator PowConsIter;
121
122 PowConsVec consd_;
123 static const std::string me_;
124bool sepIsGlobal_(const PowCons &cd) const;
125 struct SepaStats {
126 int iters;
127 int tangentcuts;
128 int optcuts;
129 int optrem;
130 double time;
131 };
132
133 struct PowPresolveStats {
134 UInt iters;
135 double time;
136 UInt conDel;
137 UInt vBnd;
138 UInt nMods;
139 PowPresolveStats() : iters(0), time(0.0), conDel(0), vBnd(0), nMods(0) {}
140 };
141
142 struct BoundTighteningStats {
143 int niters;
144 int nLP;
145 int dlb;
146 int dub;
147 double timeLP;
148 };
149
150 BoundTighteningStats bStats_;
151 PowPresolveStats pStats_;
152 SepaStats sStats_;
153
154 double LBd_;
155 double UBd_;
156 double bTol_;
157 EnvPtr env_;
158 ProblemPtr orig_;
159 ConstraintVector optCuts_;
160 double aTol_;
161 double rTol_;
162 double eTol_;
163 double vTol_;
164 ProblemPtr p_;
165 LoggerPtr log_;
166 DoubleVector tmpX_;
167 DoubleVector grad_;
168
169
170private:
171 void relaxSlot_(PowCons &cd, RelaxationPtr rel,
172 std::vector<ConstraintPtr> &slots, size_t slot,
173 ModVector &mods);
174
175 void relaxSlotsFrom_(PowCons &cd, RelaxationPtr rel,
176 std::vector<ConstraintPtr> &slots,
177 size_t from, size_t to, ModVector &mods);
178 void addCutByTan_(PowCons &cd, RelaxationPtr rel, double xv, int bound_dir,
179 ModVector &mods, size_t slot);
180 void addCutByPts_(PowCons &cd, RelaxationPtr rel, double xlb, double xub,
181 int bound_dir, ModVector &mods, bool init, size_t slot);
182 void linearize_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
183
184 void buildPosEO_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
185 void buildPosEO_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
186
187 void buildPosOO_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
188 void buildPosOO_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
189
190 void buildPosOE_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
191 void buildPosOE_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
192
193 void buildNegEO_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
194 void buildNegOO_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
195 void buildNegOE_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
196
197
198 double computeWStar_(double k) const; // Newton-Raphson solver
199
200 double computeWCross_(double k) const;
201
202
203
204
205
206
207
208
209
210
211 //Add cuts after separate_ function is called
212 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
213 RelaxationPtr rel, bool& ifcuts, PowCons *cd);
214
215 //Add Secant at root and other node for y=1/x
216 void addSecant_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
217 ModVector &mods, bool init);
218 // delete duplicate constraint
219 void dupRows_(bool *changed);
220 //select branching point for a variable based on its domain
221 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v, double bvalue);
222 // returns violation in y-1/x
223 double getViol_(const PowCons &cd, const DoubleVector &x) const;
224 //Check Feasibility of y=1/x
225 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
226 bool &should_prune, double &inf_meas);
227 // Creates root relaxation
228 void initRelax_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
229 DoubleVector &grad);
230 //from bound on y->x to bound on x->y
231 bool propPowBnds_(PowConsPtr lcd, bool *changed);
232
233 bool propPosEvenBnds_(PowConsPtr cd, bool *changed);
234 bool propPosMonotonicBnds_(PowConsPtr cd, bool *changed);
235 bool propNegEvenBnds_(PowConsPtr cd, bool *changed);
236 bool propNegMonotonicBnds_(PowConsPtr cd, bool *changed);
237 //marks dup row for deletion
238 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
239 bool *changed);
240 // Update the node relaxation by changing the bound
241 void updateRelax_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
242 DoubleVector &grad, ModVector &mods);
243
244 int updatePBnds_(VariablePtr p, double newlb, double newub, bool *changed);
245 int updatePBnds_(VariablePtr v, double newlb, double newub,
246 RelaxationPtr rel, bool mod_rel, bool *changed,
247 ModVector &p_mods, ModVector &r_mods);
248
249 bool varBndsFromCons_(bool *changed);
250 // Mathematical Evaluators
251 double getF_(double xv, double k, PowType type) const;
252 double getDf_(double xv, double k, PowType type) const;
253 double getD2f_(double xv, double k, PowType type) const;
254
255 // Safety and Validation Helpers
256 double safeX_(double xv, double k) const;
257
258
259 // Tangent Helpers
260 double getMid_(double xlb, double xub, double k, PowType type) const;
261 void addTan_(PowCons &cd, double xv, RelaxationPtr rel);
262
263 // Secant Helpers
264 bool prepSecantDomain_(double &xlb, double &xub, double k, PowType type) const;
265 void applySecantCut_(PowCons &cd, double xlb, double xub, RelaxationPtr rel,
266 ModVector &mods, bool init);
267 };
268
269} // namespace Minotaur
270#endif // MINOTAURPOWHANDLER_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 Modification.h:29
Definition Node.h:54
Definition PowHandler.h:30
Branches getBranches(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, SolutionPoolPtr s_pool)
Return branches for branching.
Definition PowHandler.cpp:1075
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 PowHandler.cpp:1417
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition PowHandler.cpp:1425
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 PowHandler.cpp:984
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition PowHandler.h:56
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition PowHandler.h:45
SolveStatus presolve(PreModQ *pre_mods, bool *changed, Solution **sol)
Initial presolve.
Definition PowHandler.cpp:1402
std::string getName() const override
Return the name of the handler.
Definition PowHandler.cpp:1421
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition PowHandler.cpp:1014
void addConstraint(ConstraintPtr)
Add constraint to be handled by this handler.
Definition PowHandler.h:42
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *is_inf)
Create root relaxation if doing incremental node relaxations.
Definition PowHandler.cpp:300
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition PowHandler.cpp:1036
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition PowHandler.cpp:1055
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition PowHandler.cpp:309
Definition Problem.h:74
Definition Relaxation.h:53
Definition SolutionPool.h:28
Definition Solution.h:30
Definition Variable.h:31
Definition AbsHandler.h:19
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 Sun Aug 9 2026