Minotaur 0.4.1
Docs for developers
QGHandler.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
15#ifndef MINOTAURQGHANDLER_H
16#define MINOTAURQGHANDLER_H
17
18#include <stack>
19
20#include "Handler.h"
21#include "Engine.h"
22#include "Problem.h"
23#include "Function.h"
24#include "Solution.h"
25
26namespace Minotaur {
27
28struct QGStats {
29 size_t nlpS;
30 size_t nlpF;
31 size_t nlpI;
32 size_t nlpIL;
33 size_t cuts;
34};
35
36
45class QGHandler : public Handler {
46
47private:
49 EnvPtr env_;
50
52 double intTol_;
53
55 LoggerPtr logger_;
56
58 static const std::string me_;
59
61 ProblemPtr minlp_;
62
64 std::vector<ConstraintPtr> nlCons_;
65
67 EnginePtr nlpe_;
68
70 std::stack<Modification *> nlpMods_;
71
73 EngineStatus nlpStatus_;
74
80 VariablePtr objVar_;
81
83 bool oNl_;
84
86 RelaxationPtr rel_;
87
89 double relobj_;
90
92 double solAbsTol_;
93
95 double solRelTol_;
96
98 double objATol_;
99
101 double objRTol_;
102
104 QGStats *stats_;
105
107 //ConstSolutionPtr rootNLPSol_;
108
109public:
118 QGHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe);
119
121 ~QGHandler();
122
124 Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr,
126 {return Branches();};
127
130 const DoubleVector &, ModVector &,
131 BrVarCandSet &, BrCandVector &, bool &) {};
132
136 {return ModificationPtr();};
137
138
139 // Base class method.
140 std::string getName() const;
141
142 // Base class method. Check if x is feasible. x has to satisfy integrality
143 // and also nonlinear constraints.
144 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
145 bool & should_prune, double &inf_meas);
146
148 SolveStatus presolve(PreModQ *, bool *, Solution **) {return Finished;};
149
152 ModVector &)
153 {return false;};
154
156 void postsolveGetX(const double *, UInt, DoubleVector *) {};
157
159 void relaxInitFull(RelaxationPtr rel, SolutionPool *sp, bool *is_inf);
160
162 void relaxInitInc(RelaxationPtr rel, SolutionPool *sp, bool *is_inf);
163
165 void relaxNodeFull(NodePtr node, RelaxationPtr rel, bool *is_inf);
166
168 void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *is_inf);
169
170
172 void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel,
173 CutManager *cutman, SolutionPoolPtr s_pool, ModVector &p_mods,
174 ModVector &r_mods, bool *sol_found, SeparationStatus *status);
175
177 void writeStats(std::ostream &out) const;
178
180 //ConstSolutionPtr getRootNLPSol_() {return rootNLPSol_;}
181
182private:
187 void addInitLinearX_(const double *x);
188
193 void cutIntSol_(ConstSolutionPtr sol, CutManager *cutMan,
194 SolutionPoolPtr s_pool, bool *sol_found,
195 SeparationStatus *status);
196
201 void fixInts_(const double *x);
202
208 void initLinear_(SolutionPool *sp, bool *isInf);
209
214 void linearAt_(FunctionPtr f, double fval, const double *x,
215 double *c, LinearFunctionPtr *lf, int *error);
216
221 void linearizeObj_();
222
227 void cutToCons_(const double *nlpx, const double *lpx, CutManager *,
228 SeparationStatus *status);
229
231 void addCut_(const double *nlpx, const double *lpx, ConstraintPtr con,
232 CutManager *cutman, SeparationStatus *status);
233
234
235 void cutsAtLpSol_(const double *lpx, CutManager *cutman,
236 SeparationStatus *status);
237
238 //void objCutAtLpSol_(const double *lpx, CutManager *cutman,
239 //SeparationStatus *status);
240
241
246 void cutToObj_(const double *nlpx, const double *lpx, CutManager *,
247 SeparationStatus *status);
248
253 void relax_(SolutionPool *sp, bool *is_inf);
254
256 void solveNLP_();
257
259 void unfixInts_();
260
265 void updateUb_(SolutionPool* s_pool, double nlpval, bool *sol_found);
266
267 };
268
269 typedef QGHandler* QGHandlerPtr;
270}
271#endif
272
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
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: 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
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: Logger.h:37
Definition: Modification.h:29
Definition: Node.h:54
Definition: Problem.h:74
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: QGHandler.h:45
void relaxNodeInc(NodePtr node, RelaxationPtr rel, bool *is_inf)
Base class method. Does nothing.
Definition: QGHandler.cpp:603
void getBranchingCandidates(RelaxationPtr, const DoubleVector &, ModVector &, BrVarCandSet &, BrCandVector &, bool &)
Does nothing.
Definition: QGHandler.h:129
bool presolveNode(RelaxationPtr, NodePtr, SolutionPoolPtr, ModVector &, ModVector &)
Does nothing.
Definition: QGHandler.h:151
void writeStats(std::ostream &out) const
Show statistics.
Definition: QGHandler.cpp:692
void relaxInitInc(RelaxationPtr rel, SolutionPool *sp, bool *is_inf)
Base class method. calls relax_().
Definition: QGHandler.cpp:591
std::string getName() const
Return the name of the handler.
Definition: QGHandler.cpp:708
QGHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe)
MS: delete after use.
Definition: QGHandler.cpp:48
SolveStatus presolve(PreModQ *, bool *, Solution **)
Does nothing.
Definition: QGHandler.h:148
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition: QGHandler.cpp:292
ModificationPtr getBrMod(BrCandPtr, DoubleVector &, RelaxationPtr, BranchDirection)
Does nothing.
Definition: QGHandler.h:134
void relaxNodeFull(NodePtr node, RelaxationPtr rel, bool *is_inf)
Base class method. Does nothing.
Definition: QGHandler.cpp:598
Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr, SolutionPoolPtr)
Does nothing.
Definition: QGHandler.h:124
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: QGHandler.cpp:632
void postsolveGetX(const double *, UInt, DoubleVector *)
Does nothing.
Definition: QGHandler.h:156
~QGHandler()
Destroy.
Definition: QGHandler.cpp:74
void relaxInitFull(RelaxationPtr rel, SolutionPool *sp, bool *is_inf)
Base class method. calls relax_().
Definition: QGHandler.cpp:586
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
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 nlpIL
Number of nlps infeasible.
Definition: QGAdvHandler.h:32
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