1 // Copyright (C) 2004, 2006 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: Carl Laird, Andreas Waechter IBM 2004-08-13 8 9 #ifndef __IPIPOPTNLP_HPP__ 10 #define __IPIPOPTNLP_HPP__ 11 12 #include "IpNLP.hpp" 13 #include "IpJournalist.hpp" 14 #include "IpNLPScaling.hpp" 15 16 namespace Ipopt 17 { 18 // forward declarations 19 class IteratesVector; 20 21 /** This is the abstract base class for classes that map 22 * the traditional NLP into 23 * something that is more useful by Ipopt. 24 * This class takes care of storing the 25 * calculated model results, handles cacheing, 26 * and (some day) takes care of addition of slacks. 27 */ 28 class IpoptNLP : public ReferencedObject 29 { 30 public: 31 /**@name Constructors/Destructors */ 32 //@{ IpoptNLP(const SmartPtr<NLPScalingObject> nlp_scaling)33 IpoptNLP(const SmartPtr<NLPScalingObject> nlp_scaling) 34 : 35 nlp_scaling_(nlp_scaling) 36 {} 37 38 /** Default destructor */ ~IpoptNLP()39 virtual ~IpoptNLP() 40 {} 41 //@} 42 43 /** Initialization method. Set the internal options and 44 * initialize internal data structures. */ Initialize(const Journalist & jnlst,const OptionsList & options,const std::string & prefix)45 virtual bool Initialize(const Journalist& jnlst, 46 const OptionsList& options, 47 const std::string& prefix) 48 { 49 bool ret = true; 50 if (IsValid(nlp_scaling_)) { 51 ret = nlp_scaling_->Initialize(jnlst, options, prefix); 52 } 53 return ret; 54 } 55 56 /**@name Possible Exceptions */ 57 //@{ 58 /** thrown if there is any error evaluating values from the nlp */ 59 DECLARE_STD_EXCEPTION(Eval_Error); 60 //@} 61 /** Initialize (create) structures for 62 * the iteration data */ 63 virtual bool InitializeStructures(SmartPtr<Vector>& x, 64 bool init_x, 65 SmartPtr<Vector>& y_c, 66 bool init_y_c, 67 SmartPtr<Vector>& y_d, 68 bool init_y_d, 69 SmartPtr<Vector>& z_L, 70 bool init_z_L, 71 SmartPtr<Vector>& z_U, 72 bool init_z_U, 73 SmartPtr<Vector>& v_L, 74 SmartPtr<Vector>& v_U 75 ) = 0; 76 77 /** Method accessing the GetWarmStartIterate of the NLP */ 78 virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate)=0; 79 80 /** Accessor methods for model data */ 81 //@{ 82 /** Objective value */ 83 virtual Number f(const Vector& x) = 0; 84 85 /** Gradient of the objective */ 86 virtual SmartPtr<const Vector> grad_f(const Vector& x) = 0; 87 88 /** Equality constraint residual */ 89 virtual SmartPtr<const Vector> c(const Vector& x) = 0; 90 91 /** Jacobian Matrix for equality constraints */ 92 virtual SmartPtr<const Matrix> jac_c(const Vector& x) = 0; 93 94 /** Inequality constraint residual (reformulated 95 * as equalities with slacks */ 96 virtual SmartPtr<const Vector> d(const Vector& x) = 0; 97 98 /** Jacobian Matrix for inequality constraints */ 99 virtual SmartPtr<const Matrix> jac_d(const Vector& x) = 0; 100 101 /** Hessian of the Lagrangian */ 102 virtual SmartPtr<const SymMatrix> h(const Vector& x, 103 Number obj_factor, 104 const Vector& yc, 105 const Vector& yd 106 ) = 0; 107 108 /** Lower bounds on x */ 109 virtual SmartPtr<const Vector> x_L() const = 0; 110 111 /** Permutation matrix (x_L_ -> x) */ 112 virtual SmartPtr<const Matrix> Px_L() const = 0; 113 114 /** Upper bounds on x */ 115 virtual SmartPtr<const Vector> x_U() const = 0; 116 117 /** Permutation matrix (x_U_ -> x */ 118 virtual SmartPtr<const Matrix> Px_U() const = 0; 119 120 /** Lower bounds on d */ 121 virtual SmartPtr<const Vector> d_L() const = 0; 122 123 /** Permutation matrix (d_L_ -> d) */ 124 virtual SmartPtr<const Matrix> Pd_L() const = 0; 125 126 /** Upper bounds on d */ 127 virtual SmartPtr<const Vector> d_U() const = 0; 128 129 /** Permutation matrix (d_U_ -> d */ 130 virtual SmartPtr<const Matrix> Pd_U() const = 0; 131 132 /** x_space */ 133 virtual SmartPtr<const VectorSpace> x_space() const = 0; 134 135 /** Accessor method to obtain the MatrixSpace for the Hessian 136 * matrix (or it's approximation) */ 137 virtual SmartPtr<const SymMatrixSpace> HessianMatrixSpace() const = 0; 138 //@} 139 140 /** Accessor method for vector/matrix spaces pointers. */ 141 virtual void GetSpaces(SmartPtr<const VectorSpace>& x_space, 142 SmartPtr<const VectorSpace>& c_space, 143 SmartPtr<const VectorSpace>& d_space, 144 SmartPtr<const VectorSpace>& x_l_space, 145 SmartPtr<const MatrixSpace>& px_l_space, 146 SmartPtr<const VectorSpace>& x_u_space, 147 SmartPtr<const MatrixSpace>& px_u_space, 148 SmartPtr<const VectorSpace>& d_l_space, 149 SmartPtr<const MatrixSpace>& pd_l_space, 150 SmartPtr<const VectorSpace>& d_u_space, 151 SmartPtr<const MatrixSpace>& pd_u_space, 152 SmartPtr<const MatrixSpace>& Jac_c_space, 153 SmartPtr<const MatrixSpace>& Jac_d_space, 154 SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space) = 0; 155 156 /** Method for adapting the variable bounds. This is called if 157 * slacks are becoming too small */ 158 virtual void AdjustVariableBounds(const Vector& new_x_L, 159 const Vector& new_x_U, 160 const Vector& new_d_L, 161 const Vector& new_d_U)=0; 162 163 /** @name Counters for the number of function evaluations. */ 164 //@{ 165 virtual Index f_evals() const = 0; 166 virtual Index grad_f_evals() const = 0; 167 virtual Index c_evals() const = 0; 168 virtual Index jac_c_evals() const = 0; 169 virtual Index d_evals() const = 0; 170 virtual Index jac_d_evals() const = 0; 171 virtual Index h_evals() const = 0; 172 //@} 173 174 /** @name Special method for dealing with the fact that the 175 * restoration phase objective function depends on the barrier 176 * parameter */ 177 //@{ 178 /** Method for telling the IpoptCalculatedQuantities class whether 179 * the objective function depends on the barrier function. This 180 * is only used for the restoration phase NLP 181 * formulation. Probably only RestoIpoptNLP should overwrite 182 * this. */ objective_depends_on_mu() const183 virtual bool objective_depends_on_mu() const 184 { 185 return false; 186 } 187 188 /** Replacement for the default objective function method which 189 * knows about the barrier parameter */ 190 virtual Number f(const Vector& x, Number mu) = 0; 191 192 /** Replacement for the default objective gradient method which 193 * knows about the barrier parameter */ 194 virtual SmartPtr<const Vector> grad_f(const Vector& x, Number mu) = 0; 195 196 /** Replacement for the default Lagrangian Hessian method which 197 * knows about the barrier parameter */ 198 virtual SmartPtr<const SymMatrix> h(const Vector& x, 199 Number obj_factor, 200 const Vector& yc, 201 const Vector& yd, 202 Number mu) = 0; 203 204 /** Provides a Hessian matrix from the correct matrix space with 205 * uninitialized values. This can be used in LeastSquareMults to 206 * obtain a "zero Hessian". */ 207 virtual SmartPtr<const SymMatrix> uninitialized_h() = 0; 208 //@} 209 210 /**@name solution routines */ 211 //@{ 212 virtual void FinalizeSolution(SolverReturn status, 213 const Vector& x, const Vector& z_L, const Vector& z_U, 214 const Vector& c, const Vector& d, 215 const Vector& y_c, const Vector& y_d, 216 Number obj_value, 217 const IpoptData* ip_data, 218 IpoptCalculatedQuantities* ip_cq)=0; 219 220 virtual bool IntermediateCallBack(AlgorithmMode mode, 221 Index iter, Number obj_value, 222 Number inf_pr, Number inf_du, 223 Number mu, Number d_norm, 224 Number regularization_size, 225 Number alpha_du, Number alpha_pr, 226 Index ls_trials, 227 SmartPtr<const IpoptData> ip_data, 228 SmartPtr<IpoptCalculatedQuantities> ip_cq)=0; 229 //@} 230 231 /** Returns the scaling strategy object */ NLP_scaling() const232 SmartPtr<NLPScalingObject> NLP_scaling() const 233 { 234 DBG_ASSERT(IsValid(nlp_scaling_)); 235 return nlp_scaling_; 236 } 237 238 private: 239 240 /**@name Default Compiler Generated Methods 241 * (Hidden to avoid implicit creation/calling). 242 * These methods are not implemented and 243 * we do not want the compiler to implement 244 * them for us, so we declare them private 245 * and do not define them. This ensures that 246 * they will not be implicitly created/called. */ 247 //@{ 248 249 /** Copy Constructor */ 250 IpoptNLP(const IpoptNLP&); 251 252 /** Overloaded Equals Operator */ 253 void operator=(const IpoptNLP&); 254 //@} 255 256 SmartPtr<NLPScalingObject> nlp_scaling_; 257 }; 258 259 } // namespace Ipopt 260 261 #endif 262