1 | // Copyright (C) 2004, International Business Machines and others. |
---|
2 | // All Rights Reserved. |
---|
3 | // This code is published under the Common Public License. |
---|
4 | // |
---|
5 | // $Id: IpOrigIpoptNLP.hpp 2 2004-10-21 01:03:09Z andreasw $ |
---|
6 | // |
---|
7 | // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 |
---|
8 | |
---|
9 | #ifndef __IPORIGIPOPTNLP_HPP__ |
---|
10 | #define __IPORIGIPOPTNLP_HPP__ |
---|
11 | |
---|
12 | #include "IpIpoptNLP.hpp" |
---|
13 | #include "IpException.hpp" |
---|
14 | |
---|
15 | namespace Ipopt |
---|
16 | { |
---|
17 | |
---|
18 | /** This class maps the traditional NLP into |
---|
19 | * something that is more useful by Ipopt. |
---|
20 | * This class takes care of storing the |
---|
21 | * calculated model results, handles cacheing, |
---|
22 | * and (some day) takes care of addition of slacks. |
---|
23 | */ |
---|
24 | class OrigIpoptNLP : public IpoptNLP |
---|
25 | { |
---|
26 | public: |
---|
27 | /**@name Constructors/Destructors */ |
---|
28 | //@{ |
---|
29 | OrigIpoptNLP(const SmartPtr<const Journalist>& jnlst, |
---|
30 | const SmartPtr<NLP>& nlp); |
---|
31 | |
---|
32 | /** Default destructor */ |
---|
33 | virtual ~OrigIpoptNLP(); |
---|
34 | //@} |
---|
35 | |
---|
36 | /**@name OrigIpoptExceptions. |
---|
37 | * ( may need to move some of these to IpoptNLP |
---|
38 | */ |
---|
39 | //@{ |
---|
40 | DECLARE_STD_EXCEPTION(TOO_FEW_DOF); |
---|
41 | //@} |
---|
42 | |
---|
43 | /** Initialize (create) structures for |
---|
44 | * the iteration data */ |
---|
45 | virtual bool InitializeStructures(SmartPtr<Vector>& x, |
---|
46 | bool init_x, |
---|
47 | SmartPtr<Vector>& y_c, |
---|
48 | bool init_y_c, |
---|
49 | SmartPtr<Vector>& y_d, |
---|
50 | bool init_y_d, |
---|
51 | SmartPtr<Vector>& z_L, |
---|
52 | bool init_z_L, |
---|
53 | SmartPtr<Vector>& z_U, |
---|
54 | bool init_z_U, |
---|
55 | SmartPtr<Vector>& v_L, |
---|
56 | bool init_v_L, |
---|
57 | SmartPtr<Vector>& v_U, |
---|
58 | bool init_v_U |
---|
59 | ); |
---|
60 | |
---|
61 | /** Accessor methods for model data */ |
---|
62 | //@{ |
---|
63 | /** Objective value */ |
---|
64 | virtual Number f(const Vector& x); |
---|
65 | |
---|
66 | /** Gradient of the objective */ |
---|
67 | virtual SmartPtr<const Vector> grad_f(const Vector& x); |
---|
68 | |
---|
69 | /** Equality constraint residual */ |
---|
70 | virtual SmartPtr<const Vector> c(const Vector& x); |
---|
71 | |
---|
72 | /** Jacobian Matrix for equality constraints |
---|
73 | * (current iteration) */ |
---|
74 | virtual SmartPtr<const Matrix> jac_c(const Vector& x); |
---|
75 | |
---|
76 | /** Inequality constraint residual (reformulated |
---|
77 | * as equalities with slacks */ |
---|
78 | virtual SmartPtr<const Vector> d(const Vector& x); |
---|
79 | |
---|
80 | /** Jacobian Matrix for inequality constraints |
---|
81 | * (current iteration) */ |
---|
82 | virtual SmartPtr<const Matrix> jac_d(const Vector& x); |
---|
83 | |
---|
84 | /** Hessian of the lagrangian |
---|
85 | * (current iteration) */ |
---|
86 | virtual SmartPtr<const SymMatrix> h(const Vector& x, |
---|
87 | Number obj_factor, |
---|
88 | const Vector& yc, |
---|
89 | const Vector& yd |
---|
90 | ); |
---|
91 | |
---|
92 | /** Lower bounds on x */ |
---|
93 | virtual SmartPtr<const Vector> x_L() |
---|
94 | { |
---|
95 | return ConstPtr(x_L_); |
---|
96 | } |
---|
97 | |
---|
98 | /** Permutation matrix (x_L_ -> x) */ |
---|
99 | virtual SmartPtr<const Matrix> Px_L() |
---|
100 | { |
---|
101 | return ConstPtr(Px_L_); |
---|
102 | } |
---|
103 | |
---|
104 | /** Upper bounds on x */ |
---|
105 | virtual SmartPtr<const Vector> x_U() |
---|
106 | { |
---|
107 | return ConstPtr(x_U_); |
---|
108 | } |
---|
109 | |
---|
110 | /** Permutation matrix (x_U_ -> x */ |
---|
111 | virtual SmartPtr<const Matrix> Px_U() |
---|
112 | { |
---|
113 | return ConstPtr(Px_U_); |
---|
114 | } |
---|
115 | |
---|
116 | /** Lower bounds on d */ |
---|
117 | virtual SmartPtr<const Vector> d_L() |
---|
118 | { |
---|
119 | return ConstPtr(d_L_); |
---|
120 | } |
---|
121 | |
---|
122 | /** Permutation matrix (d_L_ -> d) */ |
---|
123 | virtual SmartPtr<const Matrix> Pd_L() |
---|
124 | { |
---|
125 | return ConstPtr(Pd_L_); |
---|
126 | } |
---|
127 | |
---|
128 | /** Upper bounds on d */ |
---|
129 | virtual SmartPtr<const Vector> d_U() |
---|
130 | { |
---|
131 | return ConstPtr(d_U_); |
---|
132 | } |
---|
133 | |
---|
134 | /** Permutation matrix (d_U_ -> d */ |
---|
135 | virtual SmartPtr<const Matrix> Pd_U() |
---|
136 | { |
---|
137 | return ConstPtr(Pd_U_); |
---|
138 | } |
---|
139 | //@} |
---|
140 | |
---|
141 | /** Accessor method for vector/matrix spaces pointers */ |
---|
142 | virtual void GetSpaces(SmartPtr<const VectorSpace>& x_space, |
---|
143 | SmartPtr<const VectorSpace>& c_space, |
---|
144 | SmartPtr<const VectorSpace>& d_space, |
---|
145 | SmartPtr<const VectorSpace>& x_l_space, |
---|
146 | SmartPtr<const MatrixSpace>& px_l_space, |
---|
147 | SmartPtr<const VectorSpace>& x_u_space, |
---|
148 | SmartPtr<const MatrixSpace>& px_u_space, |
---|
149 | SmartPtr<const VectorSpace>& d_l_space, |
---|
150 | SmartPtr<const MatrixSpace>& pd_l_space, |
---|
151 | SmartPtr<const VectorSpace>& d_u_space, |
---|
152 | SmartPtr<const MatrixSpace>& pd_u_space, |
---|
153 | SmartPtr<const MatrixSpace>& Jac_c_space, |
---|
154 | SmartPtr<const MatrixSpace>& Jac_d_space, |
---|
155 | SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space); |
---|
156 | |
---|
157 | /** Method for adapting the variable bounds. This is called if |
---|
158 | * slacks are becoming too small */ |
---|
159 | virtual void AdjustVariableBounds(const Vector& new_x_L, |
---|
160 | const Vector& new_x_U, |
---|
161 | const Vector& new_d_L, |
---|
162 | const Vector& new_d_U); |
---|
163 | |
---|
164 | /** @name Counters for the number of function evaluations. */ |
---|
165 | //@{ |
---|
166 | virtual Index f_evals() const |
---|
167 | { |
---|
168 | return f_evals_; |
---|
169 | } |
---|
170 | virtual Index grad_f_evals() const |
---|
171 | { |
---|
172 | return grad_f_evals_; |
---|
173 | } |
---|
174 | virtual Index c_evals() const |
---|
175 | { |
---|
176 | return c_evals_; |
---|
177 | } |
---|
178 | virtual Index jac_c_evals() const |
---|
179 | { |
---|
180 | return jac_c_evals_; |
---|
181 | } |
---|
182 | virtual Index d_evals() const |
---|
183 | { |
---|
184 | return d_evals_; |
---|
185 | } |
---|
186 | virtual Index jac_d_evals() const |
---|
187 | { |
---|
188 | return jac_d_evals_; |
---|
189 | } |
---|
190 | virtual Index h_evals() const |
---|
191 | { |
---|
192 | return h_evals_; |
---|
193 | } |
---|
194 | //@} |
---|
195 | |
---|
196 | private: |
---|
197 | /** Pointer to the NLP */ |
---|
198 | SmartPtr<NLP> nlp_; |
---|
199 | |
---|
200 | /** journalist */ |
---|
201 | SmartPtr<const Journalist> jnlst_; |
---|
202 | |
---|
203 | /** Necessary Vector/Matrix spaces */ |
---|
204 | //@{ |
---|
205 | SmartPtr<VectorSpace> x_space_; |
---|
206 | |
---|
207 | SmartPtr<VectorSpace> c_space_; |
---|
208 | |
---|
209 | SmartPtr<VectorSpace> d_space_; |
---|
210 | |
---|
211 | SmartPtr<VectorSpace> x_l_space_; |
---|
212 | |
---|
213 | SmartPtr<MatrixSpace> px_l_space_; |
---|
214 | |
---|
215 | SmartPtr<VectorSpace> x_u_space_; |
---|
216 | |
---|
217 | SmartPtr<MatrixSpace> px_u_space_; |
---|
218 | |
---|
219 | SmartPtr<VectorSpace> d_l_space_; |
---|
220 | |
---|
221 | SmartPtr<MatrixSpace> pd_l_space_; |
---|
222 | |
---|
223 | SmartPtr<VectorSpace> d_u_space_; |
---|
224 | |
---|
225 | SmartPtr<MatrixSpace> pd_u_space_; |
---|
226 | |
---|
227 | SmartPtr<MatrixSpace> jac_c_space_; |
---|
228 | |
---|
229 | SmartPtr<MatrixSpace> jac_d_space_; |
---|
230 | |
---|
231 | SmartPtr<SymMatrixSpace> h_space_; |
---|
232 | //@} |
---|
233 | /**@name Storage for Model Quantities */ |
---|
234 | //@{ |
---|
235 | /** Objective function */ |
---|
236 | CachedResults<Number> f_cache_; |
---|
237 | |
---|
238 | /** Gradient of the objective function */ |
---|
239 | CachedResults<SmartPtr<Vector> > grad_f_cache_; |
---|
240 | |
---|
241 | /** Equality constraint residuals */ |
---|
242 | CachedResults<SmartPtr<Vector> > c_cache_; |
---|
243 | |
---|
244 | /** Jacobian Matrix for equality constraints |
---|
245 | * (current iteration) */ |
---|
246 | CachedResults<SmartPtr<Matrix> > jac_c_cache_; |
---|
247 | |
---|
248 | /** Inequality constraint residual (reformulated |
---|
249 | * as equalities with slacks */ |
---|
250 | CachedResults<SmartPtr<Vector> > d_cache_; |
---|
251 | |
---|
252 | /** Jacobian Matrix for inequality constraints |
---|
253 | * (current iteration) */ |
---|
254 | CachedResults<SmartPtr<Matrix> > jac_d_cache_; |
---|
255 | |
---|
256 | /** Hessian of the lagrangian |
---|
257 | * (current iteration) */ |
---|
258 | CachedResults<SmartPtr<SymMatrix> > h_cache_; |
---|
259 | |
---|
260 | /** Lower bounds on x */ |
---|
261 | SmartPtr<Vector> x_L_; |
---|
262 | |
---|
263 | /** Permutation matrix (x_L_ -> x) */ |
---|
264 | SmartPtr<Matrix> Px_L_; |
---|
265 | |
---|
266 | /** Upper bounds on x */ |
---|
267 | SmartPtr<Vector> x_U_; |
---|
268 | |
---|
269 | /** Permutation matrix (x_U_ -> x */ |
---|
270 | SmartPtr<Matrix> Px_U_; |
---|
271 | |
---|
272 | /** Lower bounds on d */ |
---|
273 | SmartPtr<Vector> d_L_; |
---|
274 | |
---|
275 | /** Permutation matrix (d_L_ -> d) */ |
---|
276 | SmartPtr<Matrix> Pd_L_; |
---|
277 | |
---|
278 | /** Upper bounds on d */ |
---|
279 | SmartPtr<Vector> d_U_; |
---|
280 | |
---|
281 | /** Permutation matrix (d_U_ -> d */ |
---|
282 | SmartPtr<Matrix> Pd_U_; |
---|
283 | //@} |
---|
284 | |
---|
285 | /**@name Default Compiler Generated Methods |
---|
286 | * (Hidden to avoid implicit creation/calling). |
---|
287 | * These methods are not implemented and |
---|
288 | * we do not want the compiler to implement |
---|
289 | * them for us, so we declare them private |
---|
290 | * and do not define them. This ensures that |
---|
291 | * they will not be implicitly created/called. */ |
---|
292 | //@{ |
---|
293 | /** Default Constructor */ |
---|
294 | OrigIpoptNLP(); |
---|
295 | |
---|
296 | /** Copy Constructor */ |
---|
297 | OrigIpoptNLP(const OrigIpoptNLP&); |
---|
298 | |
---|
299 | /** Overloaded Equals Operator */ |
---|
300 | void operator=(const OrigIpoptNLP&); |
---|
301 | //@} |
---|
302 | |
---|
303 | /** @name Counters for the function evaluations */ |
---|
304 | //@{ |
---|
305 | Index f_evals_; |
---|
306 | Index grad_f_evals_; |
---|
307 | Index c_evals_; |
---|
308 | Index jac_c_evals_; |
---|
309 | Index d_evals_; |
---|
310 | Index jac_d_evals_; |
---|
311 | Index h_evals_; |
---|
312 | //@} |
---|
313 | }; |
---|
314 | |
---|
315 | } // namespace Ipopt |
---|
316 | |
---|
317 | #endif |
---|