Minotaur 0.4.1
Docs for developers
STOAHandler.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 MINOTAURSTOAHANDLER_H
16#define MINOTAURSTOAHANDLER_H
17
18#include <stack>
19
20#include "Handler.h"
21#include "Engine.h"
22#include "MILPEngine.h"
23#include "Problem.h"
24#include "Function.h"
25#include "Timer.h"
26
27namespace Minotaur {
28
29struct STOAStats {
30 size_t nlpS;
31 size_t nlpF;
32 size_t nlpI;
33 size_t nlpIL;
34 size_t cuts;
35};
36
44class STOAHandler : public Handler {
45
46private:
48 EnvPtr env_;
49
51 double intTol_;
52
54 LoggerPtr logger_;
55
57 static const std::string me_;
58
60 ProblemPtr minlp_;
61
69 Timer *timer_;
70
72 ConstraintVector nlCons_;
73
75 EnginePtr nlpe_;
76
78 MILPEnginePtr milpe_;
79
81 //std::stack<Modification *> nlpMods_;
82
84 EngineStatus nlpStatus_;
85
91 VariablePtr objVar_;
92
94 bool oNl_;
95
96 double newUb_;
97
99 RelaxationPtr rel_;
100
101 SolutionPoolPtr solPool_;
102
104 //double relobj_;
105
107 double solAbsTol_;
108
110 double solRelTol_;
111
113 double npATol_;
114
116 double npRTol_;
117
119 UInt numCalls_;
120
122 double cbtime_;
123
125 STOAStats *stats_;
126
127
128public:
137 STOAHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe, MILPEnginePtr milpe, SolutionPoolPtr solPool);
138
140 ~STOAHandler();
141
143 Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr,
145 {return Branches();};
146
148 UInt getNumCalls() {return numCalls_;}
149
151 double getCbTime() {return cbtime_;}
152
154 void setCbTime(double timeval) {cbtime_ = timeval;}
155
158 const DoubleVector &, ModVector &,
159 BrVarCandSet &, BrCandVector &, bool &) {};
160
164 {return ModificationPtr();};
165
166 // Base class method.
167 std::string getName() const;
168
169 // Base class method. Check if x is feasible. x has to satisfy integrality
170 // and also nonlinear constraints.
172 bool &, double &) {return 0;};
173
174 //bool isFeas(const double* x);
175
177 SolveStatus presolve(PreModQ *, bool *, Solution **) {return Finished;};
178
181 ModVector &)
182 {return false;};
183
185 void postsolveGetX(const double *, UInt, DoubleVector *) {};
186
187 // Base class method. calls relax_().
189
190 // Base class method. calls relax_().
191 void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *);
192
193 // Base class method. Does nothing.
195
196 // Base class method. Does nothing.
198
199
200 // Base class method. Find cuts.
202 CutManager *, SolutionPoolPtr, ModVector &,
203 ModVector &, bool *, SeparationStatus *) {};
204
205 //void solveMILP(double* objfLb, double* objfUb,
206 //SolutionPoolPtr solPool, CutManager* cutMan);
207 void solveMILP(double* objfLb, ConstSolutionPtr* sol,
208 SolutionPoolPtr solPool, CutManager* cutMan);
209 // Show statistics.
210 void writeStats(std::ostream &out) const;
211
212 // Return the relaxation pointer
213 RelaxationPtr getRel() {return rel_;}
214
215 // Return true if the fixed NLP was feasible
216 //bool fixedNLP(const double *lpx, const double * nlpx);
217 bool fixedNLP(const double *lpx, EnginePtr &nlpe, ProblemPtr &minlp);
218
219 // Return the upper bound obtained from an integer solution
220 double newUb(std::vector<UInt> *varIdx,
221 std::vector<double>* varCoeff);
222
223 //void cutIntSol(const double *lpx, double objVal);
224
226 ConstraintConstIterator consBegin() const { return nlCons_.begin(); }
227
229 ConstraintConstIterator consEnd() const { return nlCons_.end(); }
230
231
232 void OACutToCons(const double *lpx, ConstraintPtr con, double* rhs,
233 std::vector<UInt> *varIdx, std::vector<double>* varCoeff,
234 EnginePtr nlpe);
235
236 void OACutToObj(const double *lpx, double* rhs, std::vector<UInt> *varIdx,
237 std::vector<double>* varCoeff, double ub, EnginePtr nlpe);
238
239private:
244 void addInitLinearX_(const double *x);
245
250 //void cutIntSol_(ConstSolutionPtr sol, CutManager *cutMan,
251 //SolutionPoolPtr s_pool, bool *sol_found,
252 //SeparationStatus *status);
257 void fixInts_(const double *x, ProblemPtr minlp, std::stack<Modification *> &nlpMods);
258
264 void initLinear_(bool *isInf);
265
270 void linearizeObj_();
271
272
277 void linearAt_(FunctionPtr f, double fval, const double *x,
278 double *c, LinearFunctionPtr *lf, int *error);
279
284 void cutToCons_(ConstraintPtr con, const double *nlpx, const double *lpx, double* rhs, std::vector<UInt> *varIdx,
285 std::vector<double>* varCoeff);
286
287 void addCut_(const double *nlpx, const double *lpx, ConstraintPtr con, double* rhs, std::vector<UInt> *varIdx,
288 std::vector<double>* varCoeff);
289
290 void objCutAtLpSol_(const double *lpx, double* rhs,
291 std::vector<UInt> *varIdx,
292 std::vector<double>* varCoeff, double relobj);
293
294 void consCutAtLpSol_(ConstraintPtr con, const double *lpx, double* rhs,
295 std::vector<UInt> *varIdx,
296 std::vector<double>* varCoeff);
297
302 void cutToObj_(const double *nlpx, const double *lpx,
303 double* rhs, std::vector<UInt> *varIdx,
304 std::vector<double>* varCoeff, double relobj);
305
310 void relax_(bool *is_inf);
311
313 void solveNLP_();
314
316 void unfixInts_(ProblemPtr minlp, std::stack<Modification *> &nlpMods);
317
322 void updateUb_(SolutionPoolPtr s_pool, double *nlp_val, bool *sol_found);
323
324 };
325
326 typedef STOAHandler* STOAHandlerPtr;
327}
328#endif
329
Define the base class Engine.
Get information about a Function.
Define abstract base class for handlers of various kinds.
Declare the class MILPEngine for solving MILPs and getting solution.
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
Definition: Problem.h:74
Definition: Relaxation.h:53
Handler for convex constraints, based on quesada-grossmann algorithm.
Definition: STOAHandler.h:44
ModificationPtr getBrMod(BrCandPtr, DoubleVector &, RelaxationPtr, BranchDirection)
Does nothing.
Definition: STOAHandler.h:162
UInt getNumCalls()
Return number of callbacks till now.
Definition: STOAHandler.h:148
STOAHandler(EnvPtr env, ProblemPtr minlp, EnginePtr nlpe, MILPEnginePtr milpe, SolutionPoolPtr solPool)
Default Constructor.
Definition: STOAHandler.cpp:57
void relaxNodeInc(NodePtr, RelaxationPtr, bool *)
Create an incremental relaxation for a node.
Definition: STOAHandler.h:197
void writeStats(std::ostream &out) const
Write statistics to ostream out.
Definition: STOAHandler.cpp:820
void relaxInitFull(RelaxationPtr, SolutionPool *, bool *)
Create root relaxation if doing full node relaxations.
Definition: STOAHandler.h:188
Branches getBranches(BrCandPtr, DoubleVector &, RelaxationPtr, SolutionPoolPtr)
Does nothing.
Definition: STOAHandler.h:143
bool presolveNode(RelaxationPtr, NodePtr, SolutionPoolPtr, ModVector &, ModVector &)
Does nothing.
Definition: STOAHandler.h:180
~STOAHandler()
Destroy.
Definition: STOAHandler.cpp:90
void relaxNodeFull(NodePtr, RelaxationPtr, bool *)
Create a relaxation for a node, building from scratch.
Definition: STOAHandler.h:194
void getBranchingCandidates(RelaxationPtr, const DoubleVector &, ModVector &, BrVarCandSet &, BrCandVector &, bool &)
Does nothing.
Definition: STOAHandler.h:157
ConstraintConstIterator consEnd() const
Iterate over constraints. Returns the 'end' iterator.
Definition: STOAHandler.h:229
void setCbTime(double timeval)
Set the time taken in callbacks till now.
Definition: STOAHandler.h:154
void relaxInitInc(RelaxationPtr rel, SolutionPool *, bool *)
Create root relaxation if doing incremental node relaxations.
Definition: STOAHandler.cpp:771
std::string getName() const
Return the name of the handler.
Definition: STOAHandler.cpp:837
bool isFeasible(ConstSolutionPtr, RelaxationPtr, bool &, double &)
Check if a solution is feasible.
Definition: STOAHandler.h:171
SolveStatus presolve(PreModQ *, bool *, Solution **)
Does nothing.
Definition: STOAHandler.h:177
void separate(ConstSolutionPtr, NodePtr, RelaxationPtr, CutManager *, SolutionPoolPtr, ModVector &, ModVector &, bool *, SeparationStatus *)
add cuts to separate a given point.
Definition: STOAHandler.h:201
double getCbTime()
Return the time taken in callbacks till now.
Definition: STOAHandler.h:151
ConstraintConstIterator consBegin() const
Iterate over constraints. Returns the 'begin' iterator.
Definition: STOAHandler.h:226
void postsolveGetX(const double *, UInt, DoubleVector *)
Does nothing.
Definition: STOAHandler.h:185
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: STOAHandler.h:29
size_t nlpF
Number of nlps solved.
Definition: STOAHandler.h:31
size_t cuts
Number of nlps hits engine iterations limit.
Definition: STOAHandler.h:34
size_t nlpIL
Number of nlps infeasible.
Definition: STOAHandler.h:33
size_t nlpI
Number of nlps feasible.
Definition: STOAHandler.h:32

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