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 };
92
93 struct PowCons {
94 ConstraintPtr con;
95 ConstVariablePtr iv;
96 ConstVariablePtr ov;
97 double k;
98 int p;
99 int q;
100 PowType type;
101 VariablePtr riv;
102 VariablePtr rov;
103 char sense;
104 std::vector<ConstraintPtr> secCons;
105 ConstraintVector linCons;
106
107 PowCons(ConstraintPtr newcon, ConstVariablePtr ivar,
108 ConstVariablePtr ovar, double degree, int num, int den, PowType t, char s)
109 : con(newcon), iv(ivar), ov(ovar), k(degree), p(num), q(den) , type(t) ,riv(0), rov(0),
110 sense(s), linCons() {}
111 };
112 PowCurvature getCurvature_(const PowCons &cd, double xlb, double xub) const;
113
114 typedef PowCons *PowConsPtr;
115 typedef std::vector<PowConsPtr> PowConsVec;
116 typedef PowConsVec::iterator PowConsIter;
117
118 PowConsVec consd_;
119 static const std::string me_;
120
121 struct SepaStats {
122 int iters;
123 int tangentcuts;
124 int optcuts;
125 int optrem;
126 double time;
127 };
128
129 struct PowPresolveStats {
130 UInt iters;
131 double time;
132 UInt conDel;
133 UInt vBnd;
134 UInt nMods;
135 PowPresolveStats() : iters(0), time(0.0), conDel(0), vBnd(0), nMods(0) {}
136 };
137
138 struct BoundTighteningStats {
139 int niters;
140 int nLP;
141 int dlb;
142 int dub;
143 double timeLP;
144 };
145
146 BoundTighteningStats bStats_;
147 PowPresolveStats pStats_;
148 SepaStats sStats_;
149
150 double LBd_;
151 double UBd_;
152 double bTol_;
153 EnvPtr env_;
154 ProblemPtr orig_;
155 ConstraintVector optCuts_;
156 double aTol_;
157 double rTol_;
158 double eTol_;
159 double vTol_;
160 ProblemPtr p_;
161 LoggerPtr log_;
162 DoubleVector tmpX_;
163 DoubleVector grad_;
164
165
166private:
167 // PowHandler.h — add:
168void relaxSlot_(PowCons &cd, RelaxationPtr rel, size_t slot, ModVector &mods);
169 void addSecXSq_(PowCons &cd, RelaxationPtr rel, double xlb, double xub, int bound_dir, ModVector &mods, bool init, size_t slot = 0);
170 void addTanXSq_(PowCons &cd, RelaxationPtr rel, double xv, int bound_dir);
171
172 void linearize_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
173
174 void buildPosEO_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
175 void buildPosEO_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
176
177 void buildPosOO_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
178 void buildPosOO_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
179
180 void buildPosOE_GT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
181 void buildPosOE_LT1_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
182
183 void buildNegEO_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
184 void buildNegOO_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
185 void buildNegOE_(PowCons &cd, RelaxationPtr rel, ModVector &mods, bool init);
186
187
188 double computeWStar_(double k) const; // Newton-Raphson solver
189
190 double computeWCross_(double k) const;
191
192
193
194
195
196
197
198
199
200
201 //Add cuts after separate_ function is called
202 void addCut_(VariablePtr x, VariablePtr y, double xval, double yval,
203 RelaxationPtr rel, bool& ifcuts, PowCons *cd);
204
205 //Add Secant at root and other node for y=1/x
206 void addSecant_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
207 ModVector &mods, bool init);
208 // delete duplicate constraint
209 void dupRows_(bool *changed);
210 //select branching point for a variable based on its domain
211 BranchPtr doBranch_(BranchDirection UpOrDown, ConstVariablePtr v, double bvalue);
212 // returns violation in y-1/x
213 double getViol_(const PowCons &cd, const DoubleVector &x) const;
214 //Check Feasibility of y=1/x
215 bool isFeasible_(ConstSolutionPtr sol, RelaxationPtr relaxation,
216 bool &should_prune, double &inf_meas);
217 // Creates root relaxation
218 void initRelax_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
219 DoubleVector &grad);
220 //from bound on y->x to bound on x->y
221 bool propPowBnds_(PowConsPtr lcd, bool *changed);
222
223 bool propPosEvenBnds_(PowConsPtr cd, bool *changed);
224 bool propPosMonotonicBnds_(PowConsPtr cd, bool *changed);
225 bool propNegEvenBnds_(PowConsPtr cd, bool *changed);
226 bool propNegMonotonicBnds_(PowConsPtr cd, bool *changed);
227 //marks dup row for deletion
228 bool treatDupRows_(ConstraintPtr c1, ConstraintPtr c2, double mult,
229 bool *changed);
230 // Update the node relaxation by changing the bound
231 void updateRelax_(PowCons &cd, RelaxationPtr rel, DoubleVector &tmpX,
232 DoubleVector &grad, ModVector &mods);
233
234 int updatePBnds_(VariablePtr p, double newlb, double newub, bool *changed);
235 int updatePBnds_(VariablePtr v, double newlb, double newub,
236 RelaxationPtr rel, bool mod_rel, bool *changed,
237 ModVector &p_mods, ModVector &r_mods);
238
239 bool varBndsFromCons_(bool *changed);
240 // Mathematical Evaluators
241 double getF_(double xv, double k, PowType type) const;
242 double getDf_(double xv, double k, PowType type) const;
243 double getD2f_(double xv, double k, PowType type) const;
244
245 // Safety and Validation Helpers
246 double safeX_(double xv, double k) const;
247
248
249 // Tangent Helpers
250 double getMid_(double xlb, double xub, double k, PowType type) const;
251 void addTan_(PowCons &cd, double xv, RelaxationPtr rel);
252
253 // Secant Helpers
254 bool prepSecantDomain_(double &xlb, double &xub, double k, PowType type) const;
255 void applySecantCut_(PowCons &cd, double xlb, double xub, RelaxationPtr rel,
256 ModVector &mods, bool init);
257 };
258
259} // namespace Minotaur
260#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:949
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:1291
void writeStats(std::ostream &out) const override
Write statistics to ostream out.
Definition PowHandler.cpp:1299
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:864
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:1276
std::string getName() const override
Return the name of the handler.
Definition PowHandler.cpp:1295
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition PowHandler.cpp:888
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:277
void getBranchingCandidates(RelaxationPtr rel, const DoubleVector &x, ModVector &mods, BrVarCandSet &cands, BrCandVector &gencands, bool &is_inf)
find branching candidates.
Definition PowHandler.cpp:910
ModificationPtr getBrMod(BrCandPtr cand, DoubleVector &x, RelaxationPtr rel, BranchDirection dir)
Get the modifcation that creates a given (up or down) branch.
Definition PowHandler.cpp:929
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *isInfeasible)
Create an incremental relaxation for a node.
Definition PowHandler.cpp:287
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 Sun Jul 19 2026