source: trunk/Algorithm/IpIpoptCalculatedQuantities.hpp @ 2

Last change on this file since 2 was 2, checked in by andreasw, 15 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.6 KB
Line 
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: IpIpoptCalculatedQuantities.hpp 2 2004-10-21 01:03:09Z andreasw $
6//
7// Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
8
9#ifndef __IPIPOPTCALCULATEDQUANTITIES_HPP__
10#define __IPIPOPTCALCULATEDQUANTITIES_HPP__
11
12#include "IpUtils.hpp"
13#include "IpIpoptNLP.hpp"
14#include "IpIpoptData.hpp"
15
16namespace Ipopt
17{
18
19  /** Class for all IPOPT specific calculated quantities.
20   * 
21   */
22  class IpoptCalculatedQuantities : public ReferencedObject
23  {
24  public:
25    /** Norm types */
26    enum ENormType {
27      NORM_1,
28      NORM_2,
29      NORM_MAX
30    };
31
32    /**@name Constructors/Destructors */
33    //@{
34    /** Constructor */
35    IpoptCalculatedQuantities(const SmartPtr<IpoptNLP>& ip_nlp,
36                              const SmartPtr<IpoptData>& ip_data);
37    /** Default destructor */
38    virtual ~IpoptCalculatedQuantities();
39    //@}
40
41    /** This method must be called to initialize the global
42     *  algorithmic parameters.  The parameters are taken from the
43     *  OptionsList object. */
44    bool Initialize(const Journalist& jnlst,
45                    const OptionsList& options,
46                    const std::string& prefix);
47
48    /** @name Slacks */
49    //@{
50    /** Slacks for x_L (at current iterate) */
51    SmartPtr<const Vector> curr_slack_x_L();
52    /** Slacks for x_U (at current iterate) */
53    SmartPtr<const Vector> curr_slack_x_U();
54    /** Slacks for s_L (at current iterate) */
55    SmartPtr<const Vector> curr_slack_s_L();
56    /** Slacks for s_U (at current iterate) */
57    SmartPtr<const Vector> curr_slack_s_U();
58    /** Slacks for x_L (at trial point) */
59    SmartPtr<const Vector> trial_slack_x_L();
60    /** Slacks for x_U (at trial point) */
61    SmartPtr<const Vector> trial_slack_x_U();
62    /** Slacks for s_L (at trial point) */
63    SmartPtr<const Vector> trial_slack_s_L();
64    /** Slacks for s_U (at trial point) */
65    SmartPtr<const Vector> trial_slack_s_U();
66    /** Indicating whether or not we "fudged" the slacks */
67    Index AdjustedTrialSlacks();
68    /** Reset the flags for "fudged" slacks */
69    void ResetAdjustedTrialSlacks();
70    //@}
71
72    /** @name Objective function */
73    //@{
74    /** Value of objective function (at current point) */
75    Number curr_f();
76    /** Value of objective function (at trial point) */
77    Number trial_f();
78    /** Gradient of objective function (at current point) */
79    SmartPtr<const Vector> curr_grad_f();
80    //@}
81
82    /** @name Barrier Objective Function */
83    //@{
84    /** Barrier Objective Function Value
85     * (at current iterate with current mu)
86     */
87    Number curr_barrier_obj();
88    /** Barrier Objective Function Value
89     * (at trial point with current mu)
90     */
91    Number trial_barrier_obj();
92
93    /** Gradient of barrier objective function with respect to x
94     * (at current point with current mu) */
95    SmartPtr<const Vector> curr_grad_barrier_obj_x();
96    /** Gradient of barrier objective function with respect to s
97     * (at current point with current mu) */
98    SmartPtr<const Vector> curr_grad_barrier_obj_s();
99    //@}
100
101    /** @name Constraints */
102    //@{
103    /** c(x) (at current point) */
104    SmartPtr<const Vector> curr_c();
105    /** c(x) (at trial point) */
106    SmartPtr<const Vector> trial_c();
107    /** d(x) (at current point) */
108    SmartPtr<const Vector> curr_d();
109    /** d(x) (at trial point) */
110    SmartPtr<const Vector> trial_d();
111    /** d(x) - s (at current point) */
112    SmartPtr<const Vector> curr_d_minus_s();
113    /** d(x) - s (at trial point) */
114    SmartPtr<const Vector> trial_d_minus_s();
115    /** Jacobian of c (at current point) */
116    SmartPtr<const Matrix> curr_jac_c();
117    /** Jacobian of d (at current point) */
118    SmartPtr<const Matrix> curr_jac_d();
119    /** Product of Jacobian (evaluated at current point) of C
120     *  transpose with general vector */
121    SmartPtr<const Vector> curr_jac_cT_times_vec(const Vector& vec);
122    /** Product of Jacobian (evaluated at current point) of D
123     *  transpose with general vector */
124    SmartPtr<const Vector> curr_jac_dT_times_vec(const Vector& vec);
125    /** Product of Jacobian (evaluated at current point) of C
126     *  transpose with current y_c */
127    SmartPtr<const Vector> curr_jac_cT_times_curr_y_c();
128    /** Product of Jacobian (evaluated at current point) of D
129     *  transpose with current y_d */
130    SmartPtr<const Vector> curr_jac_dT_times_curr_y_d();
131    /** Constraint Violation (at current iterate). This value should
132     *  be used in the line search, and not curr_primal_infeasibility().
133     *  What type of norm is used depends on constr_viol_normtype */
134    Number curr_constraint_violation();
135    /** Constraint Violation (at trial point). This value should
136     *  be used in the line search, and not curr_primal_infeasibility().
137     *  What type of norm is used depends on constr_viol_normtype */
138    Number trial_constraint_violation();
139    //@}
140
141    /** @name Hessian matrices */
142    //@{
143    /** exact Hessian at current iterate (uncached) */
144    SmartPtr<const SymMatrix> curr_exact_hessian();
145    /** return a matrix of the same type and structure as the Hessian
146     *  matrix, but with all "values" set to zero (uncached) */
147    SmartPtr<const SymMatrix> zero_hessian();
148    //@}
149
150    /** @name primal-dual error and its components */
151    //@{
152    /** x-part of gradient of Lagrangian function (at current point) */
153    SmartPtr<const Vector> curr_grad_lag_x();
154    /** s-part of gradient of Lagrangian function (at current point) */
155    SmartPtr<const Vector> curr_grad_lag_s();
156    /** Complementarity for x_L (for current iterate) */
157    SmartPtr<const Vector> curr_compl_x_L();
158    /** Complementarity for x_U (for current iterate) */
159    SmartPtr<const Vector> curr_compl_x_U();
160    /** Complementarity for s_L (for current iterate) */
161    SmartPtr<const Vector> curr_compl_s_L();
162    /** Complementarity for s_U (for current iterate) */
163    SmartPtr<const Vector> curr_compl_s_U();
164    /** Relaxed complementarity for x_L (for current iterate and current mu) */
165    SmartPtr<const Vector> curr_relaxed_compl_x_L();
166    /** Relaxed complementarity for x_U (for current iterate and current mu) */
167    SmartPtr<const Vector> curr_relaxed_compl_x_U();
168    /** Relaxed complementarity for s_L (for current iterate and current mu) */
169    SmartPtr<const Vector> curr_relaxed_compl_s_L();
170    /** Relaxed complementarity for s_U (for current iterate and current mu) */
171    SmartPtr<const Vector> curr_relaxed_compl_s_U();
172
173    /** Primal infeasibility in a given norm (at current iterate). */
174    Number curr_primal_infeasibility(ENormType NormType);
175    /** Primal infeasibility in a given norm (at trial point) */
176    Number trial_primal_infeasibility(ENormType NormType);
177
178    /** Dual infeasibility in a given norm (at current iterate) */
179    Number curr_dual_infeasibility(ENormType NormType);
180
181    /** Complementarity (for all complementarity conditions together)
182     *  in a given norm (at current iterate) */
183    Number curr_complementarity(Number mu, ENormType NormType);
184
185    /** Scaled total optimality error for the original NLP at the
186     *  current iterate. */
187    Number curr_nlp_error();
188
189    /** Scaled total optimality error for the barrier problem at the
190     *  current iterate. */
191    Number curr_barrier_error();
192
193    /** Primal-dual optimality error for the original NLP (at current iterate)
194     */
195    Number curr_primal_dual_error();
196    /** Relaxed primal-dual optimality error for the original NLP
197     *  (at current iterate and for current mu)
198     */
199    Number curr_relaxed_primal_dual_error();
200    //@}
201
202    /** @name Computing fraction-to-the-boundary step sizes */
203    //@{
204    /** Fraction to the boundary from (current) primal variables x and s
205     *  for a given step */
206    Number primal_frac_to_the_bound(Number tau,
207                                    const Vector& delta_x,
208                                    const Vector& delta_s);
209    /** Fraction to the boundary from (current) primal variables x and s
210     *  for internal (current) step */
211    Number curr_primal_frac_to_the_bound(Number tau);
212    /** Fraction to the boundary from (current) dual variables z and v
213     *  for a given step */
214    Number dual_frac_to_the_bound(Number tau,
215                                  const Vector& delta_z_L,
216                                  const Vector& delta_z_U,
217                                  const Vector& delta_v_L,
218                                  const Vector& delta_v_U);
219    /** Fraction to the boundary from (current) dual variables z and v
220     *  for internal (current) step */
221    Number curr_dual_frac_to_the_bound(Number tau);
222    //@}
223
224    /** @name Sigma matrices */
225    //@{
226    SmartPtr<const Vector> curr_sigma_x();
227    SmartPtr<const Vector> curr_sigma_s();
228    //@}
229
230    /** average of current values of the complementarities */
231    Number curr_avrg_compl();
232
233    /** inner_product of current barrier obj. fn. gradient with current search direction */
234    Number curr_gradBarrTDelta();
235
236    /** Compute the norm of a specific type of a set of vectors (uncached) */
237    Number
238    CalcNormOfType(IpoptCalculatedQuantities::ENormType NormType,
239                   std::vector<const Vector*> vecs);
240
241    /** Compute the norm of a specific type of two vectors (uncached) */
242    Number
243    CalcNormOfType(IpoptCalculatedQuantities::ENormType NormType,
244                   const Vector& vec1, const Vector& vec2);
245
246    /** Norm type used for calculating constraint violation */
247    ENormType constr_viol_normtype() const
248    {
249      return constr_viol_normtype_;
250    }
251
252  private:
253    /**@name Default Compiler Generated Methods
254     * (Hidden to avoid implicit creation/calling).
255     * These methods are not implemented and
256     * we do not want the compiler to implement
257     * them for us, so we declare them private
258     * and do not define them. This ensures that
259     * they will not be implicitly created/called. */
260    //@{
261    /** Default Constructor */
262    IpoptCalculatedQuantities();
263
264    /** Copy Constructor */
265    IpoptCalculatedQuantities(const IpoptCalculatedQuantities&);
266
267    /** Overloaded Equals Operator */
268    void operator=(const IpoptCalculatedQuantities&);
269    //@}
270
271    /** @name Pointers for easy access to data and NLP information */
272    //@{
273    /** Ipopt NLP object */
274    SmartPtr<IpoptNLP> ip_nlp_;
275    /** Ipopt Data object */
276    SmartPtr<IpoptData> ip_data_;
277    //@}
278
279    /** @name Algorithmic Parameters that can be set throught the
280     *  options list. Those parameters are initialize by calling the
281     *  Initialize method.*/
282    //@{
283    /** Parameter in formula for computing overall primal-dual
284     *  optimality error */
285    Number s_max_;
286    /** Weighting factor for the linear damping term added to the
287     *  barrier objective funciton. */
288    Number kappa_d_;
289    /** fractional movement allowed in bounds */
290    Number s_move_;
291    /** Norm type to be used when calculating the constraint violation */
292    ENormType constr_viol_normtype_;
293    //@}
294
295    /** @name Caches for slacks */
296    //@{
297    CachedResults< SmartPtr<Vector> > curr_slack_x_L_cache_;
298    CachedResults< SmartPtr<Vector> > curr_slack_x_U_cache_;
299    CachedResults< SmartPtr<Vector> > curr_slack_s_L_cache_;
300    CachedResults< SmartPtr<Vector> > curr_slack_s_U_cache_;
301    CachedResults< SmartPtr<Vector> > trial_slack_x_L_cache_;
302    CachedResults< SmartPtr<Vector> > trial_slack_x_U_cache_;
303    CachedResults< SmartPtr<Vector> > trial_slack_s_L_cache_;
304    CachedResults< SmartPtr<Vector> > trial_slack_s_U_cache_;
305    Index adjusted_slack_x_L_;
306    Index adjusted_slack_x_U_;
307    Index adjusted_slack_s_L_;
308    Index adjusted_slack_s_U_;
309    //@}
310
311    /** @name Cached for objective function stuff */
312    //@{
313    CachedResults<Number> curr_f_cache_;
314    CachedResults<Number> trial_f_cache_;
315    CachedResults< SmartPtr<const Vector> > curr_grad_f_cache_;
316    //@}
317
318    /** @name Caches for barrier function stuff */
319    //@{
320    CachedResults<Number> curr_barrier_obj_cache_;
321    CachedResults<Number> trial_barrier_obj_cache_;
322    CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_x_cache_;
323    CachedResults< SmartPtr<const Vector> > curr_grad_barrier_obj_s_cache_;
324    //@}
325
326    /** @name Caches for constraint stuff */
327    //@{
328    CachedResults< SmartPtr<const Vector> > curr_c_cache_;
329    CachedResults< SmartPtr<const Vector> > trial_c_cache_;
330    CachedResults< SmartPtr<const Vector> > curr_d_cache_;
331    CachedResults< SmartPtr<const Vector> > trial_d_cache_;
332    CachedResults< SmartPtr<const Vector> > curr_d_minus_s_cache_;
333    CachedResults< SmartPtr<const Vector> > trial_d_minus_s_cache_;
334    CachedResults< SmartPtr<const Matrix> > curr_jac_c_cache_;
335    CachedResults< SmartPtr<const Matrix> > curr_jac_d_cache_;
336    CachedResults< SmartPtr<const Vector> > curr_jac_cT_times_vec_cache_;
337    CachedResults< SmartPtr<const Vector> > curr_jac_dT_times_vec_cache_;
338    CachedResults<Number> curr_constraint_violation_cache_;
339    CachedResults<Number> trial_constraint_violation_cache_;
340    //@}
341
342    /** Cache for the exact Hessian */
343    CachedResults< SmartPtr<const SymMatrix> > curr_exact_hessian_cache_;
344
345    /** @name Components of primal-dual error */
346    //@{
347    CachedResults< SmartPtr<const Vector> > curr_grad_lag_x_cache_;
348    CachedResults< SmartPtr<const Vector> > curr_grad_lag_s_cache_;
349    CachedResults< SmartPtr<const Vector> > curr_compl_x_L_cache_;
350    CachedResults< SmartPtr<const Vector> > curr_compl_x_U_cache_;
351    CachedResults< SmartPtr<const Vector> > curr_compl_s_L_cache_;
352    CachedResults< SmartPtr<const Vector> > curr_compl_s_U_cache_;
353    CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_L_cache_;
354    CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_x_U_cache_;
355    CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_L_cache_;
356    CachedResults< SmartPtr<const Vector> > curr_relaxed_compl_s_U_cache_;
357    CachedResults<Number> curr_primal_infeasibility_cache_;
358    CachedResults<Number> trial_primal_infeasibility_cache_;
359    CachedResults<Number> curr_dual_infeasibility_cache_;
360    CachedResults<Number> curr_complementarity_cache_;
361    CachedResults<Number> curr_nlp_error_cache_;
362    CachedResults<Number> curr_barrier_error_cache_;
363    CachedResults<Number> curr_primal_dual_error_cache_;
364    CachedResults<Number> curr_relaxed_primal_dual_error_cache_;
365    //@}
366
367    /** @name Caches for fraction to the boundary step sizes */
368    //@{
369    CachedResults<Number> primal_frac_to_the_bound_cache_;
370    CachedResults<Number> dual_frac_to_the_bound_cache_;
371    //@}
372
373    /** @name Caches for sigma matrices */
374    //@{
375    CachedResults< SmartPtr<const Vector> > curr_sigma_x_cache_;
376    CachedResults< SmartPtr<const Vector> > curr_sigma_s_cache_;
377    //@}
378
379    /** Cache for average of current complementarity */
380    CachedResults<Number> curr_avrg_compl_cache_;
381
382    /** Cache for grad barrier obj. fn inner product with step */
383    CachedResults<Number> curr_gradBarrTDelta_cache_;
384
385    /** @name Indicator vectors required for the linear damping terms
386     *  to handle unbounded solution sets. */
387    //@{
388    /** Indicator vector for selecting the elements in x that have
389     *  only lower bounds. */
390    SmartPtr<Vector> dampind_x_L_;
391    /** Indicator vector for selecting the elements in x that have
392     *  only upper bounds. */
393    SmartPtr<Vector> dampind_x_U_;
394    /** Indicator vector for selecting the elements in s that have
395     *  only lower bounds. */
396    SmartPtr<Vector> dampind_s_L_;
397    /** Indicator vector for selecting the elements in s that have
398     *  only upper bounds. */
399    SmartPtr<Vector> dampind_s_U_;
400    //@}
401
402    /** flag indicating if Initialize method has been called (for
403     *  debugging) */
404    bool initialize_called_;
405
406    /** @name Auxiliary functions */
407    //@{
408    /** Compute new vector containing the slack to a lower bound
409     *  (uncached)
410     */
411    SmartPtr<Vector> CalcSlack_L(const Matrix& P,
412                                 const Vector& x,
413                                 const Vector& x_bound);
414    /** Compute new vector containing the slack to a upper bound
415     *  (uncached)
416     */
417    SmartPtr<Vector> CalcSlack_U(const Matrix& P,
418                                 const Vector& x,
419                                 const Vector& x_bound);
420    /** Compute barrier term at given point
421     *  (uncached)
422     */
423    Number CalcBarrierTerm(Number mu,
424                           const Vector& slack_x_L,
425                           const Vector& slack_x_U,
426                           const Vector& slack_s_L,
427                           const Vector& slack_s_U);
428
429    /** Compute complementarity for slack / multiplier pair */
430    SmartPtr<const Vector> CalcCompl(const Vector& slack,
431                                     const Vector& mult);
432
433    /** Compute fraction to the boundary parameter for lower bounds 0 */
434    Number CalcFracToZeroBound(const Vector& x,
435                               const Vector& delta,
436                               Number tau);
437
438    /** Compute fraction to the boundary parameter for lower and upper bounds */
439    Number CalcFracToBound(const Vector& slack_L,
440                           const Matrix& P_L,
441                           const Vector& slack_U,
442                           const Matrix& P_U,
443                           const Vector& delta,
444                           Number tau);
445
446    /** Compute the scaling factors for the optimality error. */
447    void ComputeOptimalityErrorScaling(const Vector& y_c, const Vector& y_d,
448                                       const Vector& z_L, const Vector& z_U,
449                                       const Vector& v_L, const Vector& v_U,
450                                       Number s_max,
451                                       Number& s_d, Number& s_c);
452
453    /** Check if slacks are becoming too small.  If slacks are
454     *  becoming too small, they are change.  The return value is the
455     *  number of corrected slacks. */
456    Index CalculateSafeSlack(SmartPtr<Vector>& slack,
457                             const SmartPtr<const Vector>& bound,
458                             const SmartPtr<const Vector>& curr_point,
459                             const SmartPtr<const Vector>& multiplier);
460
461    /** Computes the indicator vectors that can be used to filter out
462     *  those entries in the slack_... variables, that correspond to
463     *  variables with only lower and upper bounds.  This is required
464     *  for the linear damping term in the barrier objective function
465     *  to handle unbounded solution sets.  */
466    void ComputeDampingIndicators(SmartPtr<const Vector>& dampind_x_L,
467                                  SmartPtr<const Vector>& dampind_x_U,
468                                  SmartPtr<const Vector>& dampind_s_L,
469                                  SmartPtr<const Vector>& dampind_s_U);
470
471    //@}
472  };
473
474} // namespace Ipopt
475
476#endif
Note: See TracBrowser for help on using the repository browser.