Minotaur 0.4.1
Docs for developers
OAHandler.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 MINOTAUROAHANDLER_H
16#define MINOTAUROAHANDLER_H
17
18#include <stack>
19
20#include "Handler.h"
21#include "Engine.h"
22#include "Problem.h"
23#include "Function.h"
24#include "Timer.h"
25
26namespace Minotaur {
27
28struct OAStats {
29 size_t cuts;
30 size_t nlpS;
31 size_t nlpF;
32 size_t nlpI;
33 size_t nlpIL;
34 size_t milpS;
35 size_t milpIL;
36};
37
38
46class OAHandler : public Handler {
47
48private:
50 EnvPtr env_;
51
53 double intTol_;
54
56 LoggerPtr logger_;
57
59 static const std::string me_;
60
62 ProblemPtr minlp_;
63
71 Timer *timer_;
72
74 std::vector<ConstraintPtr> nlCons_;
75
77 EnginePtr nlpe_;
78
80 MILPEnginePtr milpe_;
81
83 std::stack<Modification *> nlpMods_;
84
86 EngineStatus nlpStatus_;
87
93 VariablePtr objVar_;
94
96 bool oNl_;
97
99 RelaxationPtr rel_;
100
102 double relobj_;
103
105 double solAbsTol_;
106
108 double solRelTol_;
109
111 double objATol_;
112
114 double objRTol_;
115
117 OAStats *stats_;
118
119
120public:
129 OAHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe, MILPEnginePtr milpe);
130
132 ~OAHandler();
133
135 Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr,
137 {return Branches();};
138
141 const DoubleVector &, ModVector &,
142 BrVarCandSet &, BrCandVector &, bool &) {};
143
144 std::vector<ConstraintPtr> getNonlinCons() {return nlCons_;}
145
146 VariablePtr getObjVar() {return objVar_;}
147
148 bool getObjType() { return oNl_;}
149
151 MILPEnginePtr getMILPEngine() {return milpe_;};
152
156 {return ModificationPtr();};
157
158
159 // Base class method.
160 std::string getName() const;
161
162 // Base class method. Check if x is feasible. x has to satisfy integrality
163 // and also nonlinear constraints.
164 bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation,
165 bool & should_prune, double &inf_meas);
166
168 SolveStatus presolve(PreModQ *, bool *, Solution **) {return Finished;};
169
172 ModVector &)
173 {return false;};
174
176 void postsolveGetX(const double *, UInt, DoubleVector *) {};
177
178 // Base class method. calls relax_().
180
181 // Base class method. calls relax_().
182 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *);
183
184 // Base class method. Does nothing.
186
187 // Base class method. Does nothing.
189
190
191 // Base class method. Find cuts.
192 void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel,
193 CutManager *cutman, SolutionPoolPtr s_pool, ModVector &,
194 ModVector &, bool *sol_found, SeparationStatus *status);
195
196 //void solveMILP(double* objfLb, double* objfUb,
197 //SolutionPoolPtr solPool, CutManager* cutMan);
198 void solveMILP(double* objfLb, ConstSolutionPtr* sol,
199 SolutionPoolPtr solPool, CutManager* cutMan,
200 SolveStatus &status);
201 // Show statistics.
202 void writeStats(std::ostream &out) const;
203
205 void setNonlinCons(std::vector<ConstraintPtr> nlCons) {nlCons_ = nlCons;}
206
207 void setObjVar(VariablePtr objvar) {objVar_ = objvar;}
208
209 void setObjType(bool oNl) {oNl_ = oNl;}
210
211 void setRelaxation(RelaxationPtr rel) {rel_ = rel;}
212
214 void setRelObj(double val) {relobj_ = val;}
215
216private:
221 void addInitLinearX_(const double *x);
222
227 void cutIntSol_(ConstSolutionPtr sol, CutManager *cutMan,
228 SolutionPoolPtr s_pool, bool *sol_found,
229 SeparationStatus *status);
230
235 void fixInts_(const double *x);
236
242 void initLinear_(bool *isInf);
243
248 void linearizeObj_();
249
250
255 void linearAt_(FunctionPtr f, double fval, const double *x,
256 double *c, LinearFunctionPtr *lf, int *error);
257
262 void cutToCons_(const double *nlpx, const double *lpx, CutManager *,
263 SeparationStatus *status);
264
265 void cutToConsInf_(const double *nlpx, const double *lpx, CutManager *,
266 SeparationStatus *status);
267
269 void addCut_(const double *nlpx, const double *lpx, ConstraintPtr con,
270 CutManager *cutman, SeparationStatus *status);
271
272 void addCutInf_(ConstraintPtr con, const double *nlpx, const double *lpx,
273 CutManager *cutman, SeparationStatus *status);
274
276 void cutsAtLpSol_(const double *lpx, CutManager *cutman,
277 SeparationStatus *status);
278
279
284 void cutToObj_(const double *nlpx, const double *lpx, CutManager *,
285 SeparationStatus *status);
286
291 void relax_(bool *is_inf);
292
294 void solveNLP_();
295
297 void unfixInts_();
298
303 void updateUb_(SolutionPoolPtr s_pool, double nlp_val, bool *sol_found);
304
305 };
306
307 typedef OAHandler* OAHandlerPtr;
308}
309#endif
310
Define the base class Engine.
Get information about a Function.
Define abstract base class for handlers of various kinds.
Declare the base class Modification.
Define the TimerFactory and varios Timer classes.
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: MILPEngine.h:28
Definition: Modification.h:29
Definition: Node.h:54
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: OAHandler.h:46
void postsolveGetX(const double *, UInt, DoubleVector *)
Does nothing.
Definition: OAHandler.h:176
SolveStatus presolve(PreModQ *, bool *, Solution **)
Does nothing.
Definition: OAHandler.h:168
std::string getName() const
Return the name of the handler.
Definition: OAHandler.cpp:760
~OAHandler()
Destroy.
Definition: OAHandler.cpp:88
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition: OAHandler.h:179
void separate(ConstSolutionPtr sol, NodePtr node, RelaxationPtr rel, CutManager *cutman, SolutionPoolPtr s_pool, ModVector &, ModVector &, bool *sol_found, SeparationStatus *status)
add cuts to separate a given point.
Definition: OAHandler.cpp:691
bool isFeasible(ConstSolutionPtr sol, RelaxationPtr relaxation, bool &should_prune, double &inf_meas)
Check if a solution is feasible.
Definition: OAHandler.cpp:432
bool presolveNode(RelaxationPtr, NodePtr, SolutionPoolPtr, ModVector &, ModVector &)
Does nothing.
Definition: OAHandler.h:171
void setNonlinCons(std::vector< ConstraintPtr > nlCons)
Set the nonlinear constraints.
Definition: OAHandler.h:205
OAHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe, MILPEnginePtr milpe)
Default Constructor.
Definition: OAHandler.cpp:56
Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr, SolutionPoolPtr)
Does nothing.
Definition: OAHandler.h:135
void relaxNodeInc(NodePtr, RelaxationPtr, bool *)
Create an incremental relaxation for a node.
Definition: OAHandler.h:188
void setRelObj(double val)
Set the relaxation.
Definition: OAHandler.h:214
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition: OAHandler.h:185
void writeStats(std::ostream &out) const
Write statistics to ostream out.
Definition: OAHandler.cpp:739
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *)
Create root relaxation if doing incremental node relaxations.
Definition: OAHandler.cpp:663
ModificationPtr getBrMod(BrCandPtr, DoubleVector &, RelaxationPtr, BranchDirection)
Does nothing.
Definition: OAHandler.h:154
void getBranchingCandidates(RelaxationPtr, const DoubleVector &, ModVector &, BrVarCandSet &, BrCandVector &, bool &)
Does nothing.
Definition: OAHandler.h:140
MILPEnginePtr getMILPEngine()
Returns the MILP engine.
Definition: OAHandler.h:151
Definition: Problem.h:74
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: OAHandler.h:28
size_t nlpIL
Number of nlps infeasible.
Definition: OAHandler.h:33
size_t nlpS
Number of cuts added to the MILP.
Definition: OAHandler.h:30
size_t nlpF
Number of nlps solved.
Definition: OAHandler.h:31
size_t nlpI
Number of nlps feasible.
Definition: OAHandler.h:32
size_t milpS
Number of nlps hits engine iterations limit.
Definition: OAHandler.h:34
size_t milpIL
Number of milps solved.
Definition: OAHandler.h:35

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