Minotaur 0.4.1
Docs for developers
Linearizations.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
14#ifndef MINOTAURLINEARIZATIONS_H
15#define MINOTAURLINEARIZATIONS_H
16
17#include <stack>
18
19#include "Handler.h"
20#include "Engine.h"
21#include "Problem.h"
22#include "Function.h"
23
24#include "Solution.h"
25
26namespace Minotaur {
27
28 struct LinStats {
29 size_t cuts;
30 size_t rs1Cuts;
31 size_t rs2Cuts;
32 size_t rs3Cuts;
33 size_t rs4Cuts;
34 size_t rgs1Cuts;
35 size_t rgs2Cuts;
37};
38
40
41private:
43 EnvPtr env_;
44
46 RelaxationPtr rel_;
47
49 ProblemPtr minlp_;
50
51 Timer *timer_;
52
54 double intTol_;
55
57 LoggerPtr logger_;
58
60 static const std::string me_;
61
63 std::vector<ConstraintPtr> nlCons_;
64
66 //EnginePtr lpe_;
67
69 EnginePtr nlpe_;
70
72 std::stack<Modification *> nlpMods_;
73
75 EngineStatus nlpStatus_;
76
82 //VariablePtr objVar_;
83
85 //bool oNl_;
86
88 double rs1_;
89
91 double rs2Per_;
92
93 double rs2NbhSize_;
94
96 UInt rs3_;
97
99 bool rgs1_;
100
102 double rgs2Per_;
103
105 //double relobj_;
106
108 double solAbsTol_;
109
111 double * solC_;
112
114 double * nlpx_;
115
117 double solRelTol_;
118
120 double objATol_;
121
123 double objRTol_;
124
125 double nbhSize_; //MS: make a parameter later
126
127 // populate this if any general scheme is on
128 std::vector<VariablePtr> varPtrs_;
129
130 bool oNl_;
131 // auxiliary variable for nonlinear objective
132 VariablePtr objVar_;
133
134 // index of the variables to be changed in line search
135 std::vector<UInt > changeVar_;
136
137 double * nlpDuals_;
138
139 bool hasEqCons_;
140
141 UInt numDir_;
142
143 // Is the center point found as a boundary point?
144 bool isBoundPt_;
145
147 LinStats *stats_;
148
149
150 public:
160 ProblemPtr minlp, std::vector<ConstraintPtr> nlCons,
161 VariablePtr objVar, ConstSolutionPtr sol);
162
165
167 //void rootLinearizations(const double * nlpx);
169
171
172 double * getCenter() {return solC_;}
173
175 void findCenter();
176
177 LinStats* getStats() {return stats_; };
178
183 void rootLinScheme3(EnginePtr lpe_, SeparationStatus *status);
184
185 //void setLpEngine(EnginePtr lpe) {lpe_ = lpe;};
186
187 void setNlpEngine(EnginePtr nlpe) {nlpe_ = nlpe;};
188
190 void writeStats(std::ostream &out) const;
191
192
193private:
194
196 bool addCutAtRoot_(double *x, FunctionPtr f, UInt &newConId, double UB,
197 bool isObj);
198
199 //void objCutGenScheme2_(double *xnew, double *lastGrad,
200 //double &alpha);
201
202 bool boundaryPtForObj_(double* xnew, const double *xOut,
203 std::vector<ConstraintPtr> &vioCons);
204
205 void candConsForObj_(double *xOut, std::vector<ConstraintPtr > &consToLin,
206 bool &active, bool &vio);
207
208 void candLinCons_(const double *x, std::vector<UInt > &consToLin,
209 bool &foundActive, bool &foundVio);
210
211 void cutsAtBoundary_(double *xOut);
212
214 bool findIntersectPt_(std::vector<UInt > newConsId, VariablePtr vl,
215 VariablePtr vnl, double * iP);
216
217 bool boundaryPtForCons_(double* xnew, const double *xOut,
218 std::vector<UInt > &vioCons);
219
220 void solveNLP_();
221
222
223 void setStepSize_(double &alpha, std::vector<VariablePtr > vars,
224 double *xOut, std::vector<double > unitVec);
225
226 void foundLinPt_(UInt vIdx, std::vector<UInt> varIdx, UInt pos,
227 std::vector<double> alphaSign, double varBound, double *xOut,
228 bool isAllOne);
229
234 void insertNewPt_(UInt j, UInt k, std::vector<double > & xc,
235 std::vector<double> & yc, ConstraintPtr con,
236 VariablePtr vl, VariablePtr vnl, bool & shouldCont);
237
238
239 double angleBetVectors_(double *v1, double *v2, int n);
240
241 bool isInteriorPt_(double *xOut,
242 std::vector<double* > & lastGrad,
243 double* & lastGradObj, double &alpha);
244
245 void findLinPoint_(double *xOut, std::vector<double* > & lastGrad,
246 double * &lastGradObj, double &alpha);
247
248 void genLin_(double *x, std::vector<UInt > vioConsPos,
249 std::vector<double *> &lastGrad,
250 double * &lastGradObj, double &alpha);
251
252 bool genLinObj_(double *x, double* &lastGradObj);
253
254 void genLin_(const double *x, std::vector<UInt > vioConsPos);
255
260 void linearAt_(FunctionPtr f, double fval, const double *x,
261 double *c, LinearFunctionPtr *lf, int *error);
262
264
265 bool linPart_(double *b1, UInt lVarIdx, double lVarCoeff,
266 double act, FunctionPtr f, double UB);
267
268 bool atBound_(std::vector<double > unitVec, std::vector<VariablePtr > vars);
269
270 bool boundCheck_(double dirVal, double varVal, VariablePtr v);
271
272 bool newPoint_(std::vector<VariablePtr> vars, double *xOut, double alpha,
273 std::vector<double> unitVec);
274
275 void rootLinGenScheme1_();
276
277 void ifNonlinCons_();
278
279 void ifOnlyNonlinObj_();
280
281 void rootLinGenScheme2_();
287 void rootLinScheme1_(FunctionPtr fun, double lVarCoeff, UInt lVarIdx,
288 UInt nVarIdx, double nVarCoeff, double UB, bool isObj);
289
294 void rootLinScheme2_(FunctionPtr f, double UB, double lVarCoeff,
295 UInt lVarIdx, UInt nVarIdx, bool isObj);
296
301 void rScheme2Cut_(FunctionPtr f, double UB, double &delta, double lVarCoeff,
302 double &lastSlope, UInt nVarIdx, double * npt,
303 double * grad, bool isObj);
304
305 void exploreDir_(std::vector<VariablePtr > vars, std::vector<double > dir,
306 double* xOut, double* objGrad,
307 std::vector<double* > nlconsGrad);
308
309 bool shouldStop_(EngineStatus eStatus);
310
311 bool objCut_(const double* xNew);
312
313 void search_(std::vector<VariablePtr > vars, std::vector<double* > nlconsGrad,
314 double *xOut, double *objGrad, std::vector<double > dir);
315
316 bool uniVarNlFunc_(FunctionPtr f, double &lVarCoeff, UInt & lVarIdx,
317 UInt & nVarIdx, double &nVarCoeff, bool isObj);
318
319 void updateInfo_(std::vector<double > &xc,
320 std::vector<double > &yc,
321 std::vector<double > &linVioVal, UInt j);
322 void varsInNonlinCons_();
323 };
324
326}
327#endif
328
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.
The Constraint class is used to manage a constraint.
Definition: Constraint.h:61
Definition: Engine.h:34
Definition: Environment.h:28
Definition: Function.h:37
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: Linearizations.h:39
~Linearizations()
Destroy.
Definition: Linearizations.cpp:122
void writeStats(std::ostream &out) const
Show statistics.
Definition: Linearizations.cpp:2760
void rootLinScheme3(EnginePtr lpe_, SeparationStatus *status)
Definition: Linearizations.cpp:2579
void rootLinearizationsGen()
Definition: Linearizations.cpp:806
bool rootLinearizationsUniS()
Root linearization schemes.
Definition: Linearizations.cpp:748
Linearizations(EnvPtr env, RelaxationPtr rel, ProblemPtr minlp, std::vector< ConstraintPtr > nlCons, VariablePtr objVar, ConstSolutionPtr sol)
Default Constructor.
Definition: Linearizations.cpp:54
void findCenter()
Find approximate center of the feasible region.
Definition: Linearizations.cpp:554
Definition: Logger.h:37
Definition: Problem.h:74
Definition: Relaxation.h:53
Definition: Solution.h:30
Definition: Timer.h:40
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
@ UB
Wait untill further notice.
Definition: Types.h:269
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
Definition: Linearizations.h:28
size_t rs4Cuts
Number of cuts in root scheme 3 version 1.
Definition: Linearizations.h:33
size_t rs1Cuts
Total cuts from all root schemes.
Definition: Linearizations.h:30
size_t rs3Cuts
Number of cuts in root scheme 2.
Definition: Linearizations.h:32
double linSchemesTime
Number of cuts in root gen scheme 2.
Definition: Linearizations.h:36
size_t rgs1Cuts
Number of cuts in root scheme 3 version 2.
Definition: Linearizations.h:34
size_t rs2Cuts
Number of cuts in root scheme 1.
Definition: Linearizations.h:31
size_t rgs2Cuts
Number of cuts in root gen scheme 1.
Definition: Linearizations.h:35

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