Minotaur 0.4.1
Docs for developers
qpOASESEngine.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2011 - 2025 The Minotaur Team.
5//
6
16
17
18#ifndef MINOTAURQPOASESENGINE_H
19#define MINOTAURQPOASESENGINE_H
20
21#include "QPEngine.h"
22#include "WarmStart.h"
23
24#include <qpOASES.hpp>
25
26namespace Minotaur {
27
28 class Timer;
29 class Environment;
30 class Problem;
31 class Solution;
32 typedef Environment* EnvPtr;
33 typedef Problem* ProblemPtr;
34 typedef Solution* SolutionPtr;
35
36
41 public:
42 qpOASES::SQProblem *qp;
43
44 qpOASES::SymSparseMat *H;
45 qpOASES::SparseMatrixRow *A;
46
47 qpOASES::sparse_int_t *Hir;
48 qpOASES::sparse_int_t *Hjc;
49 qpOASES::real_t *Hval;
50
51 qpOASES::sparse_int_t *Air;
52 qpOASES::sparse_int_t *Ajc;
53 qpOASES::real_t *Aval;
54
55 size_t n;
56 size_t m;
57 double *g;
58 double *lb;
59 double *ub;
60 double *lbA;
61 double *ubA;
62
63 qpOASESData (int n_, int m_, int nnzh_, int nnza_);
64 ~qpOASESData ();
65 };
66
67
69 public:
70 double *x;
71 double *y;
72 double *lb;
73 double *ub;
74 double *lbA;
75 double *ubA;
76 qpOASES::Bounds bounds;
77 qpOASES::Constraints constraints;
78 };
79
80
82 {
83 public:
86 virtual bool hasInfo() { return 1; };
87
89 virtual void write(std::ostream &) const {};
90
91 public:
92 qpOASESPoint pt;
93 };
94
99 public:
100 UInt calls;
102 double time;
103 double strTime;
104 double cTime;
107
109 UInt n_cold;
110 UInt n_strbr;
111 UInt n_dive;
112 UInt n_warm;
113
114 UInt piv_total;
115 UInt piv_cold;
116 UInt piv_strbr;
117 UInt piv_dive;
118 UInt piv_warm;
119
120 double time_total;
121 double time_cold;
122 double time_strbr;
123 double time_dive;
124 double time_warm;
125 };
126
127
143 class qpOASESEngine : public QPEngine {
144
145 public:
146 friend class Problem;
147
149 qpOASESEngine ();
150
152 qpOASESEngine (EnvPtr env);
153
156
158 void load(ProblemPtr problem);
159
161 void clear();
162
165
167 double getSolutionValue();
168
171
174
175 // Change bound on a constraint.
176 void changeBound(ConstraintPtr cons, BoundType lu, double new_val);
177
178 // Change bound on a variable.
179 void changeBound(VariablePtr var, BoundType lu, double new_val);
180
181 // Implement Engine::changeBound(VariablePtr, double, double).
182 void changeBound(VariablePtr var, double new_lb, double new_ub);
183
184 // Implement Engine::addConstraint() */
186
187 // change objective.
188 void changeObj(FunctionPtr f, double cb);
189
190 // Convert 'min f' to 'min -f'.
191 void negateObj();
192
193 // Implement Engine::changeConstraint().
194 void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf,
195 const double & ub);
196
197 // Implement Engine::getWarmStart(). // NULL for now.
199
200 // Implement Engine::getWarmStartCopy(). // NULL for now.
202
203 // Implement Engine::loadFromWarmStart().
205
206 // Implement Engine::setIterationLimit().
207 void setIterationLimit(int limit);
208
209 // Implement Engine::setDualObjLimit().
210 int setDualObjLimit(double) {return 1;};
211
212 // Implement Engine::resetIterationLimit().
213 void resetIterationLimit();
214
215 // Implement Engine::enableStrBrSetup()
216 void enableStrBrSetup();
217
218 // Implement Engine::disableStrBrSetup()
219 void disableStrBrSetup();
220
221 // Write statistics.
222 void writeStats();
223
224 // get name.
225 std::string getName() const;
226
229
230 private:
231
233 void load_();
234
239 void solve_ (int mode, double *f);
240
242 void storeSol_ (double f);
243
245 void setGradient_ ();
246
248 void setHessian_ ();
249
251 void setInitialPoint_ ();
252
254 void setVarBounds_ ();
255
257 void setConsBounds_ ();
258
260 EnvPtr env_;
261
263 ProblemPtr problem_;
264
266 SolutionPtr sol_;
267
269 bool consModed_;
270 bool hessModed_;
271
273 qpOASESData *data_;
274
276 bool resolveError_;
277
279 int iterLimit_;
280
282 int maxIterLimit_;
283
285 const double infty_;
286
288 const double bTol_;
289
291 qpOASESStats stats_;
292
294 bool strBr_;
295 bool ldWarm_;
296 UInt n_changed_;
298 double objOff_;
299
300 private:
301 void savePoint (qpOASESPoint *);
302 void restorePoint (qpOASESPoint *);
303 };
304
305 typedef qpOASESEngine* qpOASESEnginePtr;
306} // end namespace Minotaur
307
308#endif
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: Problem.h:74
Definition: QPEngine.h:24
Definition: Solution.h:30
Definition: Variable.h:31
Definition: WarmStart.h:45
Definition: qpOASESEngine.h:40
Definition: qpOASESEngine.h:143
void load(ProblemPtr problem)
Method to read the problem and initialize qpOASES.
Definition: qpOASESEngine.cpp:216
void negateObj()
Negate the objective function. Min f is changed to Min -f.
Definition: qpOASESEngine.cpp:670
std::string getName() const
Get the name.
Definition: qpOASESEngine.cpp:730
ConstWarmStartPtr getWarmStart()
Definition: qpOASESEngine.cpp:735
void changeObj(FunctionPtr f, double cb)
Change objective function.
Definition: qpOASESEngine.cpp:663
EngineStatus solve()
Solve the problem that was loaded and report the status.
Definition: qpOASESEngine.cpp:367
int setDualObjLimit(double)
Set the dual objective limit.
Definition: qpOASESEngine.h:210
EnginePtr emptyCopy()
Return an empty qpOASESEngine pointer.
Definition: qpOASESEngine.cpp:207
double getSolutionValue()
Report the solution value from the last solve.
Definition: qpOASESEngine.cpp:608
void resetIterationLimit()
Reset the iteration limit to maximum possible.
Definition: qpOASESEngine.cpp:703
void addConstraint(ConstraintPtr)
Add a new constraint to the engine.
Definition: qpOASESEngine.h:185
ConstSolutionPtr getSolution()
Report the solution.
Definition: qpOASESEngine.cpp:614
WarmStartPtr getWarmStartCopy()
Definition: qpOASESEngine.cpp:741
void clear()
Method to unload the current problem.
Definition: qpOASESEngine.cpp:225
void changeBound(ConstraintPtr cons, BoundType lu, double new_val)
Change a bound of a constraint.
Definition: qpOASESEngine.cpp:626
void loadFromWarmStart(WarmStartPtr)
Definition: qpOASESEngine.cpp:748
void enableStrBrSetup()
Make settings for strong branching.
Definition: qpOASESEngine.cpp:685
~qpOASESEngine()
Destroy.
Definition: qpOASESEngine.cpp:199
qpOASESEngine()
Default constructor.
Definition: qpOASESEngine.cpp:149
EngineStatus getStatus()
Report the status of the last solve.
Definition: qpOASESEngine.cpp:620
void setIterationLimit(int limit)
Definition: qpOASESEngine.cpp:697
void disableStrBrSetup()
Restore settings after strong branching.
Definition: qpOASESEngine.cpp:691
Definition: qpOASESEngine.h:68
Definition: qpOASESEngine.h:98
double cTime
Time taken in strong branching alone.
Definition: qpOASESEngine.h:104
UInt n_total
Number of iterations in strong branching alone.
Definition: qpOASESEngine.h:108
double strTime
Sum of time taken in all calls to solve.
Definition: qpOASESEngine.h:103
UInt strCalls
Total number of calls to solve.
Definition: qpOASESEngine.h:101
double time
Calls to solve while strong branching.
Definition: qpOASESEngine.h:102
UInt strIters
Sum of number of iterations in all calls.
Definition: qpOASESEngine.h:106
UInt iters
Time taken in copying data for strong-branching.
Definition: qpOASESEngine.h:105
Definition: qpOASESEngine.h:82
virtual bool hasInfo()
Definition: qpOASESEngine.h:86
virtual void write(std::ostream &) const
Write to an output stream.
Definition: qpOASESEngine.h:89
Definition: ActiveNodeStore.h:20
BoundType
Different types of variable-bounds.
Definition: Types.h:131
unsigned int UInt
Unsigned integer.
Definition: Types.h:30
EngineStatus
Different status that an external engine may report.
Definition: Types.h:176

Minotaur source code documented by Doxygen 1.9.4 on Fri Apr 25 2025