Minotaur 0.4.1
Docs for developers
IpoptEngine.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2008 - 2025 The Minotaur Team.
5//
6
16#ifndef MINOTAURIPOPTENGINE_H
17#define MINOTAURIPOPTENGINE_H
18
19#include "NLPEngine.h"
20#include "Solution.h"
21#include "WarmStart.h"
22
23
24namespace Ipopt {
25 class IpoptApplication;
26 class IpoptFunInterface;
27 class TNLP;
28}
29
30
31namespace Minotaur {
32
33 class Environment;
34 class IpoptEngine;
35 class Problem;
36 class Timer;
37 typedef Environment* EnvPtr;
38 typedef IpoptEngine* IpoptEnginePtr;
39 typedef Problem* ProblemPtr;
40
41 // thread based statistics
42 struct IpoptStats {
47 double ptime;
50 double strTime;
51 double time;
52 double walltime;
53 };
54
55
57 class IpoptSolution;
59 typedef const IpoptSolution* ConstIpoptSolPtr;
60
61 class IpoptSolution : public Solution {
62 public:
63
66
68 IpoptSolution(const double *x, ProblemPtr problem);
69
74 IpoptSolution(const double *x, double objval, ProblemPtr problem);
75
78
81
86 const double * getLowerDualOfVars() const {return dualXLow_;};
87
92 const double * getUpperDualOfVars() const {return dualXUp_;};
93
94 // base class
95 void setDualOfVars(const double *) { assert(!"implement me!"); };
96
98 void setDualOfVars(const double *lower, const double *upper);
99
101 void write(std::ostream &out) const;
102
103 private:
105 double *dualXLow_;
106
108 double *dualXUp_;
109 };
110
111
112 class IpoptWarmStart;
113 typedef IpoptWarmStart* IpoptWarmStartPtr;
114 typedef const IpoptWarmStart* ConstIpoptWarmStartPtr;
115
117 class IpoptWarmStart : public WarmStart {
118 public:
121
124
127
130
131 // Implement WarmStart::hasInfo().
132 bool hasInfo();
133
140 void setPoint(IpoptSolPtr sol);
141
142 // Implement WarmStart::write().
143 void write(std::ostream &out) const;
144
145 private:
147 IpoptSolPtr sol_;
148 };
149
150
151// ----------------------------------------------------------------------- //
152// ----------------------------------------------------------------------- //
153
154 class IpoptEngine : public NLPEngine {
155 public:
156
157 friend class Problem;
158
160 IpoptEngine(EnvPtr env);
161
163 ~IpoptEngine();
164
165 // Base class method
167
168 void changeBound(ConstraintPtr cons, BoundType lu, double new_val);
169
170 // Implement Engine::changeBound(VariablePtr, BoundType, double).
171 void changeBound(VariablePtr var, BoundType lu, double new_val);
172
173 // Implement Engine::changeBound(VariablePtr, double, double).
174 void changeBound(VariablePtr var, double new_lb, double new_ub);
175
176 // Implement Engine::changeConstraint().
178 double lb, double ub);
179
180 // Implement Engine::changeConstraint().
182
183 // change objective.
184 void changeObj(FunctionPtr f, double cb);
185
187 void clear();
188
190 void disableStrBrSetup();
191
194
196 void enableStrBrSetup();
197
198 // Implement Engine::fillStats()
199 void fillStats(std::vector<double> &);
200
201 // get name.
202 std::string getName() const;
203
204 // Implement Engine::getSolution().
206
207 // Implement Engine::getSolutionValue().
208 double getSolutionValue();
209
210 // Implement Engine::getStatus().
212
213 // Implement Engine::getWarmStart().
215
216 // Implement Engine::getWarmStartCopy().
218
220 void load(ProblemPtr problem);
221
222 // Implement Engine::loadFromWarmStart().
223 void loadFromWarmStart(const WarmStartPtr ws);
224
225 // Convert 'min f' to 'min -f'.
226 void negateObj();
227
228 // base class method.
229 void removeCons(std::vector<ConstraintPtr> &delcons);
230
231 // Implement Engine::resetIterationLimit().
232 void resetIterationLimit();
233
234 // Implement Engine::setIterationLimit().
235 void setIterationLimit(int limit);
236
237 // Implement Engine::setDualObjLimit().
238 int setDualObjLimit(double) {return 1;};
239
241
243
249
251 void writeStats(std::ostream &out) const;
252
253 private:
255 bool bndChanged_;
256
258 bool consChanged_;
259
261 double *dual_x_l_;
262
264 double *dual_x_u_;
265
267 double *dual_g_;
268
270 EnvPtr env_;
271
273 const double etol_;
274
277 bool justLoaded_;
278
280 LoggerPtr logger_;
281
283 static const int maxIterLimit_ = 3000;
284
286 static const std::string me_;
287
288 Ipopt::IpoptApplication *myapp_;
289
290 // usually gets freed automatically when myapp_ is deleted.
291 // In case myapp_->Optimize or myapp_->Reoptimize are
292 // not called even once, then we have to free it (see
293 // IpoptStats::opt, reopt).
295
302 bool prepareWs_;
303
305 bool presolve_();
306
308 ProblemPtr problem_;
309
316 IpoptSolPtr sol_;
317
319 IpoptStats *stats_;
320
322 bool strBr_;
323
328 Timer *timer_;
329
334 bool useWs_;
335
338
340 IpoptWarmStartPtr wsSb_;
341
343 void setOptionsForProb_();
344 };
345}
346
347#endif
Declare NLPEngine Class for solving nonlinear problems using a nonlinear solver.
Implement base class Solution.
Definition: IpoptEngineTnlp.h:20
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
Definition: IpoptEngine.h:154
void addConstraint(ConstraintPtr c)
Add a new constraint to the engine.
Definition: IpoptEngine.cpp:304
void setOptionsForRepeatedSolve()
Set options to solve the NLP repeatedly, with few changes.
Definition: IpoptEngine.cpp:583
double getSolutionValue()
Get the solution value.
Definition: IpoptEngine.cpp:413
void changeConstraint(ConstraintPtr con, LinearFunctionPtr lf, double lb, double ub)
Change the linear function, and the bounds of a constraint.
Definition: IpoptEngine.cpp:324
WarmStartPtr getWarmStartCopy()
Definition: IpoptEngine.cpp:402
ConstWarmStartPtr getWarmStart()
Definition: IpoptEngine.cpp:397
void loadFromWarmStart(const WarmStartPtr ws)
Definition: IpoptEngine.cpp:455
IpoptEngine(EnvPtr env)
Default constructor.
Definition: IpoptEngine.cpp:228
void fillStats(std::vector< double > &)
Accumulate statistics from different threads in a common data.
Definition: IpoptEngine.cpp:783
void disableStrBrSetup()
Restore settings after strong branching.
Definition: IpoptEngine.cpp:360
void writeStats(std::ostream &out) const
Write statistics.
Definition: IpoptEngine.cpp:798
void setOptionsForSingleSolve()
Definition: IpoptEngine.cpp:614
int setDualObjLimit(double)
Set the dual objective limit.
Definition: IpoptEngine.h:238
void enableStrBrSetup()
Make settings for strong branching.
Definition: IpoptEngine.cpp:375
void changeObj(FunctionPtr f, double cb)
Change objective function.
Definition: IpoptEngine.cpp:335
void load(ProblemPtr problem)
Load the problem into IPOPT. We create the TNLP interface to IPOPT.
Definition: IpoptEngine.cpp:423
EngineStatus getStatus()
Get the status of the last solve command.
Definition: IpoptEngine.cpp:418
void setIterationLimit(int limit)
Definition: IpoptEngine.cpp:559
void clear()
Clear the loaded problem, if any, from the engine.
Definition: IpoptEngine.cpp:340
void resetIterationLimit()
Reset the iteration limit to maximum possible.
Definition: IpoptEngine.cpp:554
void negateObj()
Negate the objective function. Min f is changed to Min -f.
Definition: IpoptEngine.cpp:479
EngineStatus solve()
Definition: IpoptEngine.cpp:628
~IpoptEngine()
Destroy.
Definition: IpoptEngine.cpp:274
void changeBound(ConstraintPtr cons, BoundType lu, double new_val)
Change a bound of a constraint.
Definition: IpoptEngine.cpp:309
std::string getName() const
Get the name.
Definition: IpoptEngine.cpp:384
EnginePtr emptyCopy()
Return an empty IpoptEngine pointer.
Definition: IpoptEngine.cpp:370
ConstSolutionPtr getSolution()
Get the solution obtained after solving the problem.
Definition: IpoptEngine.cpp:389
void removeCons(std::vector< ConstraintPtr > &delcons)
Delete constraints from the engine.
Definition: IpoptEngine.cpp:549
Definition: IpoptEngine.h:61
~IpoptSolution()
Destroy.
Definition: IpoptEngine.cpp:105
void setDualOfVars(const double *)
Copy values of dual variables of variables.
Definition: IpoptEngine.h:95
IpoptSolution()
Default constructor.
Definition: IpoptEngine.cpp:49
void write(std::ostream &out) const
Write to an output.
Definition: IpoptEngine.cpp:138
const double * getUpperDualOfVars() const
Definition: IpoptEngine.h:92
IpoptSolution(const double *x, ProblemPtr problem)
Construct a solution for a problem from an array of doubles.
const double * getLowerDualOfVars() const
Definition: IpoptEngine.h:86
Class for saving and using Warm-start information in Ipopt.
Definition: IpoptEngine.h:117
void write(std::ostream &out) const
Write to an output stream.
Definition: IpoptEngine.cpp:219
IpoptSolPtr getPoint()
Return the soluton that can be used as starting point.
Definition: IpoptEngine.cpp:199
void setPoint(IpoptSolPtr sol)
Definition: IpoptEngine.cpp:214
IpoptWarmStart()
Default constructor.
Definition: IpoptEngine.cpp:178
~IpoptWarmStart()
Destroy.
Definition: IpoptEngine.cpp:192
bool hasInfo()
Definition: IpoptEngine.cpp:204
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Definition: Logger.h:37
Definition: NLPEngine.h:37
Base class for nonlinear functions.
Definition: NonlinearFunction.h:31
Definition: Problem.h:74
Definition: Solution.h:30
Definition: Timer.h:40
Definition: Variable.h:31
Definition: WarmStart.h:45
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
Definition: IpoptEngine.h:42
double ptime
Sum of time taken in all calls to presolve.
Definition: IpoptEngine.h:47
UInt opt
No. of calls to Ipopt's Optimize.
Definition: IpoptEngine.h:44
UInt reopt
No. of calls to Ipopt's ReOptimize.
Definition: IpoptEngine.h:45
UInt calls
Total number of calls to solve.
Definition: IpoptEngine.h:43
UInt strIters
Number of iterations in strong branching alone.
Definition: IpoptEngine.h:49
UInt iters
Sum of number of iterations in all calls.
Definition: IpoptEngine.h:46
double strTime
time taken in strong branching alone.
Definition: IpoptEngine.h:50
double time
Sum of time taken in all calls to solve.
Definition: IpoptEngine.h:51
UInt strCalls
Calls to solve while strong branching.
Definition: IpoptEngine.h:48

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