Minotaur 0.4.1
Docs for developers
QGHandlerAdvance.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2009 - 2025 The Minotaur Team.
5//
6
13#ifndef MINOTAURQGHANDLERADVANCE_H
14#define MINOTAURQGHANDLERADVANCE_H
15
16#include <stack>
17
18#include "Handler.h"
19#include "Engine.h"
20#include "Problem.h"
21#include "Function.h"
22#include "Linearizations.h"
23#include "PerspCutGenerator.h"
24
25#include "Solution.h"
26
27namespace Minotaur {
28// MS: remove the ones not needed
29struct QGStats {
30 size_t nlpS;
31 size_t nlpM;
32 size_t nlpF;
33 size_t nlpI;
34 size_t nlpIL;
35 size_t cuts;
36 size_t fracCuts;
37 //size_t preNodes; /// Number of nodes on which presolving is carried out
38 //size_t preNodesInf; /// Number of nodes on which presolving is carried out and became infeasible
39 //size_t fix; /// Number of nodes on which vars from implication are fixed
40 //size_t prInf;
41 //size_t prAct;
42};
43
44
53class QGHandlerAdvance : public Handler {
54
55private:
57 EnvPtr env_;
58
60 double intTol_;
61
63 LoggerPtr logger_;
64
66 static const std::string me_;
67
69 ProblemPtr minlp_;
70
71 Timer *timer_;
72
74 std::vector<ConstraintPtr> nlCons_;
75
76 std::vector<ConstraintPtr> highDualCons_;
77
79 EnginePtr nlpe_;
80
81 EnginePtr lpe_;
82
84 std::stack<Modification *> nlpMods_;
85
87 EngineStatus nlpStatus_;
88
89 void prModNLP_(const double *x);
90
91 void perspectiveCutsObjX_(const double *lpx, CutManager *, SeparationStatus *status);
92
93 void perspectiveCutsConsX_(const double *nlpx, const double *lpx, CutManager *, SeparationStatus *status);
94
95 void prFeasibleInactive_(bool binVal, UInt bIdx, UInt i, FunctionPtr f, const double *x, double * y, double * prPt, const double * ptToCut, CutManagerPtr cutMan);
96
97 bool prInfeasibility_(bool bisect, bool binVal, const double *x, double * y, double * prPt, const double *ptToCut, UInt i, bool isObj, double relVal, UInt bIdx, FunctionPtr f);
98
99 void shortestDist_(ConstSolutionPtr sol);
100
101 double * solC_;
107 VariablePtr objVar_;
108
110 bool oNl_;
111
113 RelaxationPtr rel_;
114
116 double relobj_;
117
119 double solAbsTol_;
120
122 double solRelTol_;
123
125 double objAbsTol_;
126
128 double objRelTol_;
129
130 LinearizationsPtr extraLin_;
131
132 int rs3_;
133
134 double maxVioPer_;
135
136 double objVioMul_;
137
138 UInt nodeDep_;
139
140 std::vector<double > consDual_;
141
142 bool findC_;
143
144 std::string cutMethod_;
145
146 //double lpdist_;
147 //EngineStatus shortestNlpStatus_;
148
149 int lastNodeId_;
150
151 UInt lastNodeIdPre_;
152
154 double lpdist_;
155 EngineStatus shortestNlpStatus_;
156
157 std::unordered_map<VariablePtr, std::forward_list<impliVar>> impli0_;
158 std::unordered_map<VariablePtr, std::forward_list<impliVar>> impli1_;
159
160 PerspCutGeneratorPtr prCutGen_;
161
163 QGStats *stats_;
164
165public:
174 QGHandlerAdvance(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe);
175
178
180 Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr,
182 {return Branches();};
183
186 const DoubleVector &, ModVector &,
187 BrVarCandSet &, BrCandVector &, bool &) {};
188
192 {return ModificationPtr();};
193
194
195 // Base class method.
196 std::string getName() const;
197
198 // Base class method. Check if x is feasible. x has to satisfy integrality
199 // and also nonlinear constraints.
200 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
201 bool & should_prune, double &inf_meas);
202
204 SolveStatus presolve(PreModQ *, bool *, Solution **sol) {return Finished;};
205
208 ModVector &)
209 {return false;};
210
212 void postsolveGetX(const double *, UInt, DoubleVector *) {};
213
215 void relaxInitFull(RelaxationPtr rel, bool *is_inf);
216
218 void relaxInitInc(RelaxationPtr rel, bool *is_inf);
219
221 void relaxNodeFull(NodePtr node, RelaxationPtr rel, bool *is_inf);
222
224 void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *is_inf);
225
226
228 void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel,
229 CutManager *cutman, SolutionPoolPtr s_pool, ModVector &p_mods,
230 ModVector &r_mods, bool *sol_found, SeparationStatus *status);
231
232
233 void setLpEngine(EnginePtr lpe) {lpe_ = lpe;};
234
236 void writeStats(std::ostream &out) const;
237
239 //ConstSolutionPtr getRootNLPSol_() {return rootNLPSol_;}
240
241private:
247 void addInitLinearX_(ConstSolutionPtr sol);
248
249 void addCutAtRoot_(ConstraintPtr con, const double * x, bool isObj);
250
251 void dualBasedCons_(ConstSolutionPtr sol);
252
257 //void cutIntSol_(ConstSolutionPtr sol, CutManager *cutMan,
258 void cutIntSol_(const double *lpx, CutManager *cutMan,
259 SolutionPoolPtr s_pool, bool *sol_found,
260 SeparationStatus *status);
261
262
263 void ESHTypeCut_(const double *lpx, CutManager *cutMan,
264 ConstraintPtr con);
265
266
267 void gradientIneq_(const double *nlpx, const double *lpx,
268 CutManager *cutman, SeparationStatus *status,
269 ConstraintPtr con, bool isObj);
270
271 void findCenter_();
276 void fixInts_(const double *x);
277
283 void initLinear_(bool *isInf);
284
289 void linearAt_(FunctionPtr f, double fval, const double *x,
290 double *c, LinearFunctionPtr *lf, int *error);
291
296 void linearizeObj_();
297
302 void cutToCons_(const double *nlpx, const double *lpx, CutManager *,
303 SeparationStatus *status);
304
306 void addCut_(const double *nlpx, const double *lpx, ConstraintPtr con,
307 CutManager *cutman, SeparationStatus *status);
308
309 void ECPTypeCut_(const double *x, CutManager *, ConstraintPtr con, double act);
310
311 void consCutsAtLpSol_(const double *lpx, CutManager *cutman,
312 SeparationStatus *status);
313
314 void genLin_(const double *x, std::vector<UInt> vioCons, CutManager *cutMan);
315
316 bool isIntFeas_(const double* x);
317
318 void perspReform_();
319
320 void maxVio_(ConstSolutionPtr sol, NodePtr node,
321 CutManager *cutMan,
322 SeparationStatus *status);
323
324 void ESHTypeCut_(const double *lpx, CutManager *cutMan);
325
326 void objCutAtLpSol_(const double *lpx, CutManager *,
327 SeparationStatus *status, bool fracNode);
328 //void objCutAtLpSol_(const double *lpx, CutManager *cutman,
329 //SeparationStatus *status);
330
331
332 bool boundaryPtForCons_(double* xnew, const double *xOut,
333 std::vector<UInt > &vioCons);
338 void cutToObj_(const double *nlpx, const double *lpx, CutManager *,
339 SeparationStatus *status);
340
345 void relax_(bool *is_inf);
346
347 void solveCenterNLP_(EnginePtr nlpe);
348
350 void solveNLP_();
351
353 void undoMods_();
354
359 void updateUb_(SolutionPoolPtr s_pool, double nlpval, bool *sol_found);
360
361 //void shortestDist_(ConstSolutionPtr sol);
362
363 };
364
365 typedef QGHandlerAdvance* QGHandlerAdvancePtr;
366}
367#endif
368
Define the base class Engine.
Get information about a Function.
Define abstract base class for handlers of various kinds.
Declare the base class Modification.
Implement base class Solution.
Base class for describing candidates for branching on a node in branch-and-bound.
Definition: BrCand.h:32
Abstract base class to manage cuts in the relaxation.
Definition: CutManager.h:42
Definition: Engine.h:34
Definition: Environment.h:28
Definition: Function.h:37
Base class for handling specific types of constraints or objective.
Definition: Handler.h:49
Definition: Linearizations.h:39
Definition: Logger.h:37
Definition: Modification.h:29
Definition: Node.h:54
Definition: PerspCutGenerator.h:37
Definition: Problem.h:74
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: QGHandlerAdvance.h:53
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition: QGHandlerAdvance.cpp:1166
ModificationPtr getBrMod(BrCandPtr, DoubleVector &, RelaxationPtr, BranchDirection)
Does nothing.
Definition: QGHandlerAdvance.h:190
~QGHandlerAdvance()
Destroy.
Definition: QGHandlerAdvance.cpp:105
QGHandlerAdvance(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe)
Default Constructor.
Definition: QGHandlerAdvance.cpp:56
std::string getName() const
Return the name of the handler.
Definition: QGHandlerAdvance.cpp:3115
void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel, CutManager *cutman, SolutionPoolPtr s_pool, ModVector &p_mods, ModVector &r_mods, bool *sol_found, SeparationStatus *status)
Base class method. Find cuts.
Definition: QGHandlerAdvance.cpp:2155
void relaxNodeFull(NodePtr node, RelaxationPtr rel, bool *is_inf)
Base class method. Does nothing.
Definition: QGHandlerAdvance.cpp:1603
void relaxInitFull(RelaxationPtr rel, bool *is_inf)
Base class method. calls relax_().
Definition: QGHandlerAdvance.cpp:1589
SolveStatus presolve(PreModQ *, bool *, Solution **sol)
Does nothing.
Definition: QGHandlerAdvance.h:204
bool presolveNode(RelaxationPtr, NodePtr, SolutionPoolPtr, ModVector &, ModVector &)
Does nothing.
Definition: QGHandlerAdvance.h:207
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *is_inf)
Base class method. Does nothing.
Definition: QGHandlerAdvance.cpp:1609
void postsolveGetX(const double *, UInt, DoubleVector *)
Does nothing.
Definition: QGHandlerAdvance.h:212
void getBranchingCandidates(RelaxationPtr, const DoubleVector &, ModVector &, BrVarCandSet &, BrCandVector &, bool &)
Does nothing.
Definition: QGHandlerAdvance.h:185
void relaxInitInc(RelaxationPtr rel, bool *is_inf)
Base class method. calls relax_().
Definition: QGHandlerAdvance.cpp:1595
Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr, SolutionPoolPtr)
Does nothing.
Definition: QGHandlerAdvance.h:180
void writeStats(std::ostream &out) const
Show statistics.
Definition: QGHandlerAdvance.cpp:3068
Definition: Relaxation.h:53
Definition: SolutionPool.h:28
Definition: Solution.h:30
Definition: Timer.h:40
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
EngineStatus
Different status that an external engine may report.
Definition: Types.h:176
SolveStatus
Different states an algorithm like branch-and-bound can be in.
Definition: Types.h:158
Definition: QGAdvHandler.h:28
size_t nlpI
Number of nlps feasible.
Definition: QGAdvHandler.h:31
size_t cuts
Number of nlps hits engine iterations limit.
Definition: QGAdvHandler.h:33
size_t nlpM
Number of nlps solved.
Definition: QGHandlerAdvance.h:31
size_t nlpIL
Number of nlps infeasible.
Definition: QGAdvHandler.h:32
size_t fracCuts
Number of cuts at int feas nodes.
Definition: QGHandlerAdvance.h:36
size_t nlpF
Number of nlps solved.
Definition: QGAdvHandler.h:30

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025