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: IpRestoIpoptNLP.hpp 416 2005-07-29 19:11:41Z andreasw $ |
---|
6 | // |
---|
7 | // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 |
---|
8 | |
---|
9 | #ifndef __IPRESTOIPOPTNLP_HPP__ |
---|
10 | #define __IPRESTOIPOPTNLP_HPP__ |
---|
11 | |
---|
12 | #include "IpIpoptNLP.hpp" |
---|
13 | #include "IpIpoptData.hpp" |
---|
14 | #include "IpIpoptCalculatedQuantities.hpp" |
---|
15 | #include "IpCompoundMatrix.hpp" |
---|
16 | #include "IpCompoundSymMatrix.hpp" |
---|
17 | #include "IpCompoundVector.hpp" |
---|
18 | #include "IpIdentityMatrix.hpp" |
---|
19 | #include "IpDiagMatrix.hpp" |
---|
20 | #include "IpZeroMatrix.hpp" |
---|
21 | |
---|
22 | namespace Ipopt |
---|
23 | { |
---|
24 | |
---|
25 | DeclareIpoptType(RestoIpoptNLP); |
---|
26 | |
---|
27 | /** This class maps the traditional NLP into |
---|
28 | * something that is more useful by Ipopt. |
---|
29 | * This class takes care of storing the |
---|
30 | * calculated model results, handles cacheing, |
---|
31 | * and (some day) takes care of addition of slacks. |
---|
32 | */ |
---|
33 | class RestoIpoptNLP : public IpoptNLP |
---|
34 | { |
---|
35 | public: |
---|
36 | /**@name Constructors/Destructors */ |
---|
37 | //@{ |
---|
38 | RestoIpoptNLP(IpoptNLP& orig_ip_nlp, |
---|
39 | IpoptData& orig_ip_data, |
---|
40 | IpoptCalculatedQuantities& orig_ip_cq); |
---|
41 | |
---|
42 | /** Default destructor */ |
---|
43 | ~RestoIpoptNLP(); |
---|
44 | //@} |
---|
45 | |
---|
46 | /** Initialize - overloaded from IpoptNLP */ |
---|
47 | virtual bool Initialize(const Journalist& jnlst, |
---|
48 | const OptionsList& options, |
---|
49 | const std::string& prefix); |
---|
50 | |
---|
51 | /** Initialize (create) structures for |
---|
52 | * the iteration data */ |
---|
53 | virtual bool InitializeStructures(SmartPtr<Vector>& x, |
---|
54 | bool init_x, |
---|
55 | SmartPtr<Vector>& y_c, |
---|
56 | bool init_y_c, |
---|
57 | SmartPtr<Vector>& y_d, |
---|
58 | bool init_y_d, |
---|
59 | SmartPtr<Vector>& z_L, |
---|
60 | bool init_z_L, |
---|
61 | SmartPtr<Vector>& z_U, |
---|
62 | bool init_z_U, |
---|
63 | SmartPtr<Vector>& v_L, |
---|
64 | SmartPtr<Vector>& v_U |
---|
65 | ); |
---|
66 | |
---|
67 | /** Solution Routines - overloaded from IpoptNLP*/ |
---|
68 | //@{ |
---|
69 | void FinalizeSolution(SolverReturn status, |
---|
70 | const Vector& x, const Vector& z_L, const Vector& z_U, |
---|
71 | const Vector& c, const Vector& d, |
---|
72 | const Vector& y_c, const Vector& y_d, |
---|
73 | Number obj_value) |
---|
74 | {} |
---|
75 | //@} |
---|
76 | |
---|
77 | /** Accessor methods for model data */ |
---|
78 | //@{ |
---|
79 | /** Method for telling IpoptCalculatedQuantities that the |
---|
80 | * restoration phase objective function depends on the barrier |
---|
81 | * parameter */ |
---|
82 | virtual bool objective_depends_on_mu() const |
---|
83 | { |
---|
84 | return true; |
---|
85 | } |
---|
86 | |
---|
87 | /** Objective value (incorrect version for restoration phase) */ |
---|
88 | virtual Number f(const Vector& x) |
---|
89 | { |
---|
90 | DBG_ASSERT(false && "ERROR: In RestoIpoptNLP f() is called without mu!"); |
---|
91 | return 0.; |
---|
92 | } |
---|
93 | |
---|
94 | /** Objective value */ |
---|
95 | virtual Number f(const Vector& x, Number mu); |
---|
96 | |
---|
97 | /** Gradient of the objective (incorrect version for restoration phase) */ |
---|
98 | virtual SmartPtr<const Vector> grad_f(const Vector& x) |
---|
99 | { |
---|
100 | DBG_ASSERT(false && "ERROR: In RestoIpoptNLP grad_f() is called without mu!"); |
---|
101 | return NULL; |
---|
102 | } |
---|
103 | |
---|
104 | /** Gradient of the objective */ |
---|
105 | virtual SmartPtr<const Vector> grad_f(const Vector& x, Number mu); |
---|
106 | |
---|
107 | /** Equality constraint residual */ |
---|
108 | virtual SmartPtr<const Vector> c(const Vector& x); |
---|
109 | |
---|
110 | /** Jacobian Matrix for equality constraints */ |
---|
111 | virtual SmartPtr<const Matrix> jac_c(const Vector& x); |
---|
112 | |
---|
113 | /** Inequality constraint residual (reformulated |
---|
114 | * as equalities with slacks */ |
---|
115 | virtual SmartPtr<const Vector> d(const Vector& x); |
---|
116 | |
---|
117 | /** Jacobian Matrix for inequality constraints */ |
---|
118 | virtual SmartPtr<const Matrix> jac_d(const Vector& x); |
---|
119 | |
---|
120 | /** Hessian of the Lagrangian (incorrect version for restoration |
---|
121 | * phase) */ |
---|
122 | virtual SmartPtr<const SymMatrix> h(const Vector& x, |
---|
123 | Number obj_factor, |
---|
124 | const Vector& yc, |
---|
125 | const Vector& yd |
---|
126 | ) |
---|
127 | { |
---|
128 | DBG_ASSERT(false && "ERROR: In RestoIpoptNLP h() is called without mu!"); |
---|
129 | return NULL; |
---|
130 | } |
---|
131 | |
---|
132 | /** Hessian of the Lagrangian */ |
---|
133 | virtual SmartPtr<const SymMatrix> h(const Vector& x, |
---|
134 | Number obj_factor, |
---|
135 | const Vector& yc, |
---|
136 | const Vector& yd, |
---|
137 | Number mu); |
---|
138 | |
---|
139 | /** Lower bounds on x */ |
---|
140 | virtual SmartPtr<const Vector> x_L() |
---|
141 | { |
---|
142 | return GetRawPtr(x_L_); |
---|
143 | } |
---|
144 | |
---|
145 | /** Permutation matrix (x_L_ -> x) */ |
---|
146 | virtual SmartPtr<const Matrix> Px_L() |
---|
147 | { |
---|
148 | return GetRawPtr(Px_L_); |
---|
149 | } |
---|
150 | |
---|
151 | /** Upper bounds on x */ |
---|
152 | virtual SmartPtr<const Vector> x_U() |
---|
153 | { |
---|
154 | return GetRawPtr(x_U_); |
---|
155 | } |
---|
156 | |
---|
157 | /** Permutation matrix (x_U_ -> x */ |
---|
158 | virtual SmartPtr<const Matrix> Px_U() |
---|
159 | { |
---|
160 | return GetRawPtr(Px_U_); |
---|
161 | } |
---|
162 | |
---|
163 | /** Lower bounds on d */ |
---|
164 | virtual SmartPtr<const Vector> d_L() |
---|
165 | { |
---|
166 | return GetRawPtr(d_L_); |
---|
167 | } |
---|
168 | |
---|
169 | /** Permutation matrix (d_L_ -> d) */ |
---|
170 | virtual SmartPtr<const Matrix> Pd_L() |
---|
171 | { |
---|
172 | return GetRawPtr(Pd_L_); |
---|
173 | } |
---|
174 | |
---|
175 | /** Upper bounds on d */ |
---|
176 | virtual SmartPtr<const Vector> d_U() |
---|
177 | { |
---|
178 | return GetRawPtr(d_U_); |
---|
179 | } |
---|
180 | |
---|
181 | /** Permutation matrix (d_U_ -> d */ |
---|
182 | virtual SmartPtr<const Matrix> Pd_U() |
---|
183 | { |
---|
184 | return GetRawPtr(Pd_U_); |
---|
185 | } |
---|
186 | //@} |
---|
187 | |
---|
188 | /** Accessor method for vector/matrix spaces pointers */ |
---|
189 | virtual void GetSpaces(SmartPtr<const VectorSpace>& x_space, |
---|
190 | SmartPtr<const VectorSpace>& c_space, |
---|
191 | SmartPtr<const VectorSpace>& d_space, |
---|
192 | SmartPtr<const VectorSpace>& x_l_space, |
---|
193 | SmartPtr<const MatrixSpace>& px_l_space, |
---|
194 | SmartPtr<const VectorSpace>& x_u_space, |
---|
195 | SmartPtr<const MatrixSpace>& px_u_space, |
---|
196 | SmartPtr<const VectorSpace>& d_l_space, |
---|
197 | SmartPtr<const MatrixSpace>& pd_l_space, |
---|
198 | SmartPtr<const VectorSpace>& d_u_space, |
---|
199 | SmartPtr<const MatrixSpace>& pd_u_space, |
---|
200 | SmartPtr<const MatrixSpace>& Jac_c_space, |
---|
201 | SmartPtr<const MatrixSpace>& Jac_d_space, |
---|
202 | SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space); |
---|
203 | /** Method for adapting the variable bounds. This is called if |
---|
204 | * slacks are becoming too small */ |
---|
205 | virtual void AdjustVariableBounds(const Vector& new_x_L, |
---|
206 | const Vector& new_x_U, |
---|
207 | const Vector& new_d_L, |
---|
208 | const Vector& new_d_U); |
---|
209 | |
---|
210 | /** @name Accessor method for the information of the original NLP. |
---|
211 | * These methods are not overloaded from IpoptNLP */ |
---|
212 | //@{ |
---|
213 | IpoptNLP& OrigIpNLP() const |
---|
214 | { |
---|
215 | return *orig_ip_nlp_; |
---|
216 | } |
---|
217 | IpoptData& OrigIpData() const |
---|
218 | { |
---|
219 | return *orig_ip_data_; |
---|
220 | } |
---|
221 | IpoptCalculatedQuantities& OrigIpCq() const |
---|
222 | { |
---|
223 | return *orig_ip_cq_; |
---|
224 | } |
---|
225 | //@} |
---|
226 | |
---|
227 | /** Accessor Method for obtaining the Rho penalization factor for |
---|
228 | * the ell_1 norm */ |
---|
229 | Number Rho() const |
---|
230 | { |
---|
231 | return rho_; |
---|
232 | } |
---|
233 | |
---|
234 | /** @name Counters for the number of function evaluations. */ |
---|
235 | //@{ |
---|
236 | virtual Index f_evals() const |
---|
237 | { |
---|
238 | return f_evals_; |
---|
239 | } |
---|
240 | virtual Index grad_f_evals() const |
---|
241 | { |
---|
242 | return grad_f_evals_; |
---|
243 | } |
---|
244 | virtual Index c_evals() const |
---|
245 | { |
---|
246 | return c_evals_; |
---|
247 | } |
---|
248 | virtual Index jac_c_evals() const |
---|
249 | { |
---|
250 | return jac_c_evals_; |
---|
251 | } |
---|
252 | virtual Index d_evals() const |
---|
253 | { |
---|
254 | return d_evals_; |
---|
255 | } |
---|
256 | virtual Index jac_d_evals() const |
---|
257 | { |
---|
258 | return jac_d_evals_; |
---|
259 | } |
---|
260 | virtual Index h_evals() const |
---|
261 | { |
---|
262 | return h_evals_; |
---|
263 | } |
---|
264 | //@} |
---|
265 | |
---|
266 | /** Methods for IpoptType */ |
---|
267 | //@{ |
---|
268 | /** Called by IpoptType to register the options */ |
---|
269 | static void RegisterOptions(SmartPtr<RegisteredOptions> roptions); |
---|
270 | //@} |
---|
271 | |
---|
272 | private: |
---|
273 | /** @name Pointers for the original NLP information. */ |
---|
274 | //@{ |
---|
275 | /** Pointer to the original IpoptNLP */ |
---|
276 | SmartPtr<IpoptNLP> orig_ip_nlp_; |
---|
277 | |
---|
278 | /** Pointer to the original IpoptData */ |
---|
279 | SmartPtr<IpoptData> orig_ip_data_; |
---|
280 | |
---|
281 | /** Pointer to the original IpoptCalculatedQuantities */ |
---|
282 | SmartPtr<IpoptCalculatedQuantities> orig_ip_cq_; |
---|
283 | //@} |
---|
284 | |
---|
285 | /** Necessary Vector/Matrix spaces */ |
---|
286 | //@{ |
---|
287 | SmartPtr<CompoundVectorSpace> x_space_; |
---|
288 | |
---|
289 | SmartPtr<const VectorSpace> c_space_; |
---|
290 | |
---|
291 | SmartPtr<const VectorSpace> d_space_; |
---|
292 | |
---|
293 | SmartPtr<CompoundVectorSpace> x_l_space_; |
---|
294 | |
---|
295 | SmartPtr<CompoundMatrixSpace> px_l_space_; |
---|
296 | |
---|
297 | SmartPtr<const VectorSpace> x_u_space_; |
---|
298 | |
---|
299 | SmartPtr<CompoundMatrixSpace> px_u_space_; |
---|
300 | |
---|
301 | SmartPtr<const VectorSpace> d_l_space_; |
---|
302 | |
---|
303 | SmartPtr<const MatrixSpace> pd_l_space_; |
---|
304 | |
---|
305 | SmartPtr<const VectorSpace> d_u_space_; |
---|
306 | |
---|
307 | SmartPtr<const MatrixSpace> pd_u_space_; |
---|
308 | |
---|
309 | SmartPtr<CompoundMatrixSpace> jac_c_space_; |
---|
310 | |
---|
311 | SmartPtr<CompoundMatrixSpace> jac_d_space_; |
---|
312 | |
---|
313 | SmartPtr<CompoundSymMatrixSpace> h_space_; |
---|
314 | //@} |
---|
315 | |
---|
316 | /**@name Storage for Model Quantities */ |
---|
317 | //@{ |
---|
318 | /** Lower bounds on x */ |
---|
319 | SmartPtr<CompoundVector> x_L_; |
---|
320 | |
---|
321 | /** Permutation matrix (x_L_ -> x) */ |
---|
322 | SmartPtr<CompoundMatrix> Px_L_; |
---|
323 | |
---|
324 | /** Upper bounds on x */ |
---|
325 | SmartPtr<const Vector> x_U_; |
---|
326 | |
---|
327 | /** Permutation matrix (x_U_ -> x) */ |
---|
328 | SmartPtr<CompoundMatrix> Px_U_; |
---|
329 | |
---|
330 | /** Lower bounds on d */ |
---|
331 | SmartPtr<const Vector> d_L_; |
---|
332 | |
---|
333 | /** Permutation matrix (d_L_ -> d) */ |
---|
334 | SmartPtr<const Matrix> Pd_L_; |
---|
335 | |
---|
336 | /** Upper bounds on d */ |
---|
337 | SmartPtr<const Vector> d_U_; |
---|
338 | |
---|
339 | /** Permutation matrix (d_U_ -> d */ |
---|
340 | SmartPtr<const Matrix> Pd_U_; |
---|
341 | //@} |
---|
342 | |
---|
343 | /** @name Values particular to the restoration phase problem statement */ |
---|
344 | //@{ |
---|
345 | /** Penalty parameter for the \$l_1\$ norm */ |
---|
346 | Number rho_; |
---|
347 | /** scaling factor for eta calculation */ |
---|
348 | Number eta_factor_; |
---|
349 | /** exponent for mu in eta calculation */ |
---|
350 | Number eta_mu_exponent_; |
---|
351 | // TODO in the following we should use pointers to CONST values |
---|
352 | /** Scaling factors for the \$x\$ part of the regularization term */ |
---|
353 | SmartPtr<Vector> dr_x_; |
---|
354 | SmartPtr<DiagMatrix> DR_x_; //TODO We can get rid of one of the dr DR |
---|
355 | /** \$x\$ part of the reference point in the regularization term */ |
---|
356 | SmartPtr<Vector> x_ref_; |
---|
357 | //@} |
---|
358 | |
---|
359 | /** Method to calculate eta, the factor for the regularization term */ |
---|
360 | Number Eta(Number mu) const; |
---|
361 | |
---|
362 | /**@name Default Compiler Generated Methods |
---|
363 | * (Hidden to avoid implicit creation/calling). |
---|
364 | * These methods are not implemented and |
---|
365 | * we do not want the compiler to implement |
---|
366 | * them for us, so we declare them private |
---|
367 | * and do not define them. This ensures that |
---|
368 | * they will not be implicitly created/called. */ |
---|
369 | //@{ |
---|
370 | /** Default Constructor */ |
---|
371 | RestoIpoptNLP(); |
---|
372 | |
---|
373 | /** Copy Constructor */ |
---|
374 | RestoIpoptNLP(const RestoIpoptNLP&); |
---|
375 | |
---|
376 | /** Overloaded Equals Operator */ |
---|
377 | void operator=(const RestoIpoptNLP&); |
---|
378 | //@} |
---|
379 | |
---|
380 | /** Flag indicating if evalution of the objective should be |
---|
381 | * performed for every restoration phase objective function |
---|
382 | * evaluation. */ |
---|
383 | bool evaluate_orig_obj_at_resto_trial_; |
---|
384 | |
---|
385 | /** Flag indicating if initialization method has been called */ |
---|
386 | bool initialized_; |
---|
387 | |
---|
388 | /** @name Counters for the function evaluations */ |
---|
389 | //@{ |
---|
390 | Index f_evals_; |
---|
391 | Index grad_f_evals_; |
---|
392 | Index c_evals_; |
---|
393 | Index jac_c_evals_; |
---|
394 | Index d_evals_; |
---|
395 | Index jac_d_evals_; |
---|
396 | Index h_evals_; |
---|
397 | //@} |
---|
398 | }; |
---|
399 | |
---|
400 | } // namespace Ipopt |
---|
401 | |
---|
402 | #endif |
---|