1 // Copyright (C) 2008 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id$
6 //
7 // Authors:  Andreas Waechter           IBM    2008-08-31
8 //               derived from IpIpoptCalculatedQuantities.hpp
9 
10 #ifndef __IPINEXACTCQ_HPP__
11 #define __IPINEXACTCQ_HPP__
12 
13 #include "IpIpoptCalculatedQuantities.hpp"
14 #include "IpInexactData.hpp"
15 
16 namespace Ipopt
17 {
18 
19   /** Class for all Chen-Goldfarb penalty method specific calculated
20    *  quantities.
21    */
22   class InexactCq : public IpoptAdditionalCq
23   {
24   public:
25 
26     /**@name Constructors/Destructors */
27     //@{
28     /** Constructor */
29     InexactCq(IpoptNLP* ip_nlp,
30               IpoptData* ip_data,
31               IpoptCalculatedQuantities* ip_cq);
32 
33     /** Default destructor */
34     virtual ~InexactCq();
35     //@}
36 
37     /** This method must be called to initialize the global
38      *  algorithmic parameters.  The parameters are taken from the
39      *  OptionsList object. */
40     bool Initialize(const Journalist& jnlst,
41                     const OptionsList& options,
42                     const std::string& prefix);
43 
44     /** Methods for IpoptType */
45     //@{
46     static void RegisterOptions(const SmartPtr<RegisteredOptions>& roptions);
47     //@}
48 
49     /** Gradient of infeasibility w.r.t. x.  Jacobian of equality
50      *  constraints transpose times the equality constraints plus
51      *  Jacobian of the inequality constraints transpose times the
52      *  inequality constraints (including slacks). */
53     SmartPtr<const Vector> curr_jac_cdT_times_curr_cdminuss();
54 
55     /** Vector of all inequality slacks for doing the slack-based scaling */
56     SmartPtr<const Vector> curr_scaling_slacks();
57 
58     /** Vector with the slack-scaled d minus s inequalities */
59     SmartPtr<const Vector> curr_slack_scaled_d_minus_s();
60 
61     /** Scaled norm of Ac */
62     Number curr_scaled_Ac_norm();
63 
64     /** Scaled, squared norm of A */
65     Number curr_scaled_A_norm2();
66 
67     /** Compute the 2-norm of a slack-scaled vector with x and s
68      *  component */
69     Number slack_scaled_norm(const Vector& x, const Vector &s);
70 
71     /** Compute x component of the W*vec product for the current
72      *  Hessian and a vector */
73     SmartPtr<const Vector> curr_W_times_vec_x(const Vector& vec_x);
74 
75     /** Compute s component of the W*vec product for the current
76      *  Hessian and a vector */
77     SmartPtr<const Vector> curr_W_times_vec_s(const Vector& vec_s);
78 
79     /** Compute x component of the W*u product for the current values.
80      *  u here is the tangential step. */
81     SmartPtr<const Vector> curr_Wu_x();
82 
83     /** Compute s component of the W*u product for the current values.
84      *  u here is the tangential step. */
85     SmartPtr<const Vector> curr_Wu_s();
86 
87     /** Compute the u^T*W*u product for the current values.  u here is the
88     tangential step. */
89     Number curr_uWu();
90 
91     /** Compute the c-component of the product of the current
92      *  constraint Jacobian with the current normal step */
93     SmartPtr<const Vector> curr_jac_times_normal_c();
94 
95     /** Compute the d-component of the product of the current
96      *  constraint Jacobian with the current normal step */
97     SmartPtr<const Vector> curr_jac_times_normal_d();
98 
99   private:
100     /**@name Default Compiler Generated Methods
101      * (Hidden to avoid implicit creation/calling).
102      * These methods are not implemented and
103      * we do not want the compiler to implement
104      * them for us, so we declare them private
105      * and do not define them. This ensures that
106      * they will not be implicitly created/called. */
107     //@{
108     /** Default Constructor */
109     InexactCq();
110 
111     /** Copy Constructor */
112     InexactCq(const InexactCq&);
113 
114     /** Overloaded Equals Operator */
115     void operator=(const InexactCq&);
116     //@}
117 
118     /** @name Pointers for easy access to data and NLP information. To
119      *  avoid circular references of Smart Pointers, we use a regular
120      *  pointer here. */
121     //@{
122     IpoptNLP* ip_nlp_;
123     IpoptData* ip_data_;
124     IpoptCalculatedQuantities* ip_cq_;
125     //@}
126 
127     /** Method to easily access Inexact data */
InexData()128     InexactData& InexData()
129     {
130       InexactData& inexact_data =
131         static_cast<InexactData&>(ip_data_->AdditionalData());
132       DBG_ASSERT(dynamic_cast<InexactData*>(&ip_data_->AdditionalData()));
133       return inexact_data;
134     }
135 
136     /** @name Caches */
137     //@{
138     CachedResults<SmartPtr<const Vector> > curr_jac_cdT_times_curr_cdminuss_cache_;
139     CachedResults<SmartPtr<const Vector> > curr_scaling_slacks_cache_;
140     CachedResults<SmartPtr<const Vector> > curr_slack_scaled_d_minus_s_cache_;
141     CachedResults<Number> curr_scaled_Ac_norm_cache_;
142     CachedResults<Number> slack_scaled_norm_cache_;
143     CachedResults<SmartPtr<const Vector> > curr_W_times_vec_x_cache_;
144     CachedResults<SmartPtr<const Vector> > curr_W_times_vec_s_cache_;
145     CachedResults<SmartPtr<const Vector> > curr_Wu_x_cache_;
146     CachedResults<SmartPtr<const Vector> > curr_Wu_s_cache_;
147     CachedResults<Number> curr_uWu_cache_;
148     CachedResults<SmartPtr<const Vector> > curr_jac_times_normal_c_cache_;
149     CachedResults<SmartPtr<const Vector> > curr_jac_times_normal_d_cache_;
150     //@}
151 
152     /** Upper bound on slack-based scaling factors */
153     Number slack_scale_max_;
154   };
155 
156 } // namespace Ipopt
157 
158 #endif
159