- Main Page
- Classes
- Files

- File List
- File Members

# src/Interfaces/IpTNLPAdapter.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2008 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Eclipse Public License.
    00004 //
    00005 // $Id: IpTNLPAdapter.hpp 1861 2010-12-21 21:34:47Z andreasw $
    00006 //
    00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
    00008
    00009 #ifndef __IPTNLPADAPTER_HPP__
    00010 #define __IPTNLPADAPTER_HPP__
    00011
    00012 #include "IpNLP.hpp"
    00013 #include "IpTNLP.hpp"
    00014 #include "IpOrigIpoptNLP.hpp"
    00015 #include <list>
    00016
    00017 namespace Ipopt
    00018 {
    00019
    00020   // forward declarations
    00021   class ExpansionMatrix;
    00022   class ExpansionMatrixSpace;
    00023   class IteratesVector;
    00024   class TDependencyDetector;
    00025
    00030   class TNLPAdapter : public NLP
    00031   {
    00032   public:
    00036     TNLPAdapter(const SmartPtr<TNLP> tnlp,
    00037                 const SmartPtr<const Journalist> jnlst = NULL);
    00038
    00040     virtual ~TNLPAdapter();
    00042
    00045     DECLARE_STD_EXCEPTION(INVALID_TNLP);
    00046     DECLARE_STD_EXCEPTION(ERROR_IN_TNLP_DERIVATIVE_TEST);
    00048
    00051     virtual bool ProcessOptions(const OptionsList& options,
    00052                                 const std::string& prefix);
    00053
    00056     virtual bool GetSpaces(SmartPtr<const VectorSpace>& x_space,
    00057                            SmartPtr<const VectorSpace>& c_space,
    00058                            SmartPtr<const VectorSpace>& d_space,
    00059                            SmartPtr<const VectorSpace>& x_l_space,
    00060                            SmartPtr<const MatrixSpace>& px_l_space,
    00061                            SmartPtr<const VectorSpace>& x_u_space,
    00062                            SmartPtr<const MatrixSpace>& px_u_space,
    00063                            SmartPtr<const VectorSpace>& d_l_space,
    00064                            SmartPtr<const MatrixSpace>& pd_l_space,
    00065                            SmartPtr<const VectorSpace>& d_u_space,
    00066                            SmartPtr<const MatrixSpace>& pd_u_space,
    00067                            SmartPtr<const MatrixSpace>& Jac_c_space,
    00068                            SmartPtr<const MatrixSpace>& Jac_d_space,
    00069                            SmartPtr<const SymMatrixSpace>& Hess_lagrangian_space);
    00070
    00072     virtual bool GetBoundsInformation(const Matrix& Px_L,
    00073                                       Vector& x_L,
    00074                                       const Matrix& Px_U,
    00075                                       Vector& x_U,
    00076                                       const Matrix& Pd_L,
    00077                                       Vector& d_L,
    00078                                       const Matrix& Pd_U,
    00079                                       Vector& d_U);
    00080
    00083     virtual bool GetStartingPoint(
    00084       SmartPtr<Vector> x,
    00085       bool need_x,
    00086       SmartPtr<Vector> y_c,
    00087       bool need_y_c,
    00088       SmartPtr<Vector> y_d,
    00089       bool need_y_d,
    00090       SmartPtr<Vector> z_L,
    00091       bool need_z_L,
    00092       SmartPtr<Vector> z_U,
    00093       bool need_z_U
    00094     );
    00095
    00098     virtual bool GetWarmStartIterate(IteratesVector& warm_start_iterate);
    00100
    00103     virtual bool Eval_f(const Vector& x, Number& f);
    00104
    00105     virtual bool Eval_grad_f(const Vector& x, Vector& g_f);
    00106
    00107     virtual bool Eval_c(const Vector& x, Vector& c);
    00108
    00109     virtual bool Eval_jac_c(const Vector& x, Matrix& jac_c);
    00110
    00111     virtual bool Eval_d(const Vector& x, Vector& d);
    00112
    00113     virtual bool Eval_jac_d(const Vector& x, Matrix& jac_d);
    00114
    00115     virtual bool Eval_h(const Vector& x,
    00116                         Number obj_factor,
    00117                         const Vector& yc,
    00118                         const Vector& yd,
    00119                         SymMatrix& h);
    00120
    00121     virtual void GetScalingParameters(
    00122       const SmartPtr<const VectorSpace> x_space,
    00123       const SmartPtr<const VectorSpace> c_space,
    00124       const SmartPtr<const VectorSpace> d_space,
    00125       Number& obj_scaling,
    00126       SmartPtr<Vector>& x_scaling,
    00127       SmartPtr<Vector>& c_scaling,
    00128       SmartPtr<Vector>& d_scaling) const;
    00130
    00133     virtual void FinalizeSolution(SolverReturn status,
    00134                                   const Vector& x,
    00135                                   const Vector& z_L, const Vector& z_U,
    00136                                   const Vector& c, const Vector& d,
    00137                                   const Vector& y_c, const Vector& y_d,
    00138                                   Number obj_value,
    00139                                   const IpoptData* ip_data,
    00140                                   IpoptCalculatedQuantities* ip_cq);
    00141
    00142     virtual bool IntermediateCallBack(AlgorithmMode mode,
    00143                                       Index iter, Number obj_value,
    00144                                       Number inf_pr, Number inf_du,
    00145                                       Number mu, Number d_norm,
    00146                                       Number regularization_size,
    00147                                       Number alpha_du, Number alpha_pr,
    00148                                       Index ls_trials,
    00149                                       const IpoptData* ip_data,
    00150                                       IpoptCalculatedQuantities* ip_cq);
    00152
    00154     virtual void
    00155     GetQuasiNewtonApproximationSpaces(SmartPtr<VectorSpace>& approx_space,
    00156                                       SmartPtr<Matrix>& P_approx);
    00157
    00159     enum FixedVariableTreatmentEnum
    00160     {
    00161       MAKE_PARAMETER=0,
    00162       MAKE_CONSTRAINT,
    00163       RELAX_BOUNDS
    00164     };
    00165
    00167     enum DerivativeTestEnum
    00168     {
    00169       NO_TEST=0,
    00170       FIRST_ORDER_TEST,
    00171       SECOND_ORDER_TEST,
    00172       ONLY_SECOND_ORDER_TEST
    00173     };
    00174
    00176     enum JacobianApproxEnum
    00177     {
    00178       JAC_EXACT=0,
    00179       JAC_FINDIFF_VALUES
    00180     };
    00181
    00183     bool CheckDerivatives(DerivativeTestEnum deriv_test,
    00184                           Index deriv_test_start_index);
    00185
    00188     static void RegisterOptions(SmartPtr<RegisteredOptions> roptions);
    00190
    00192     SmartPtr<TNLP> tnlp() const
    00193     {
    00194       return tnlp_;
    00195     }
    00196
    00203     void ResortX(const Vector& x, Number* x_orig);
    00204     void ResortG(const Vector& c, const Vector& d, Number *g_orig);
    00205     void ResortBnds(const Vector& x_L, Number* x_L_orig,
    00206                     const Vector& x_U, Number* x_U_orig);
    00208
    00209   private:
    00219     TNLPAdapter(const TNLPAdapter&);
    00220
    00222     void operator=(const TNLPAdapter&);
    00224
    00227     bool DetermineDependentConstraints(Index n_x_var,
    00228                                        const Index* x_not_fixed_map,
    00229                                        const Number* x_l, const Number* x_u,
    00230                                        const Number* g_l, const Number* g_u,
    00231                                        Index n_c, const Index* c_map,
    00232                                        std::list<Index>& c_deps);
    00233
    00236     SmartPtr<TNLP> tnlp_;
    00237
    00239     SmartPtr<const Journalist> jnlst_;
    00240
    00243     SmartPtr<TDependencyDetector> dependency_detector_;
    00244
    00248     Number nlp_lower_bound_inf_;
    00250     Number nlp_upper_bound_inf_;
    00252     FixedVariableTreatmentEnum fixed_variable_treatment_;
    00253     /* Determines relaxation of fixing bound for RELAX_BOUNDS. */
    00254     Number bound_relax_factor_;
    00255     /* Maximal slack for one-sidedly bounded variables.  If a
    00256      *  variable has only one bound, say a lower bound xL, then an
    00257      *  upper bound xL + max_onesided_bound_slack_.  If this value is
    00258      *  zero, no upper bound is added. */
    00259     /* Took this out:  Number max_onesided_bound_slack_; */
    00262     DerivativeTestEnum derivative_test_;
    00264     Number derivative_test_perturbation_;
    00267     Number derivative_test_tol_;
    00270     bool derivative_test_print_all_;
    00272     Index derivative_test_first_index_;
    00275     bool warm_start_same_structure_;
    00277     HessianApproximationType hessian_approximation_;
    00279     Index num_linear_variables_;
    00281     JacobianApproxEnum jacobian_approximation_;
    00283     Number findiff_perturbation_;
    00285     Number point_perturbation_radius_;
    00288     bool dependency_detection_with_rhs_;
    00289
    00291     Number tol_;
    00293
    00297     Index n_full_x_;
    00299     Index n_full_g_;
    00301     Index nz_jac_c_;
    00304     Index nz_jac_c_no_extra_;
    00306     Index nz_jac_d_;
    00308     Index nz_full_jac_g_;
    00310     Index nz_full_h_;
    00312     Index nz_h_;
    00314     Index n_x_fixed_;
    00316
    00318     TNLP::IndexStyleEnum index_style_;
    00319
    00322     SmartPtr<const VectorSpace> x_space_;
    00323     SmartPtr<const VectorSpace> c_space_;
    00324     SmartPtr<const VectorSpace> d_space_;
    00325     SmartPtr<const VectorSpace> x_l_space_;
    00326     SmartPtr<const MatrixSpace> px_l_space_;
    00327     SmartPtr<const VectorSpace> x_u_space_;
    00328     SmartPtr<const MatrixSpace> px_u_space_;
    00329     SmartPtr<const VectorSpace> d_l_space_;
    00330     SmartPtr<const MatrixSpace> pd_l_space_;
    00331     SmartPtr<const VectorSpace> d_u_space_;
    00332     SmartPtr<const MatrixSpace> pd_u_space_;
    00333     SmartPtr<const MatrixSpace> Jac_c_space_;
    00334     SmartPtr<const MatrixSpace> Jac_d_space_;
    00335     SmartPtr<const SymMatrixSpace> Hess_lagrangian_space_;
    00337
    00340     Number* full_x_;
    00341     Number* full_lambda_;
    00342     Number* full_g_;
    00343     Number* jac_g_;
    00344     Number* c_rhs_;
    00346
    00349     TaggedObject::Tag x_tag_for_iterates_;
    00350     TaggedObject::Tag y_c_tag_for_iterates_;
    00351     TaggedObject::Tag y_d_tag_for_iterates_;
    00352     TaggedObject::Tag x_tag_for_g_;
    00353     TaggedObject::Tag x_tag_for_jac_g_;
    00355
    00358     bool update_local_x(const Vector& x);
    00359     bool update_local_lambda(const Vector& y_c, const Vector& y_d);
    00361
    00365     bool internal_eval_g(bool new_x);
    00366     bool internal_eval_jac_g(bool new_x);
    00368
    00373     void initialize_findiff_jac(const Index* iRow, const Index* jCol);
    00375
    00380     SmartPtr<ExpansionMatrix> P_x_full_x_;
    00381     SmartPtr<ExpansionMatrixSpace> P_x_full_x_space_;
    00382
    00384     SmartPtr<ExpansionMatrix> P_x_x_L_;
    00385     SmartPtr<ExpansionMatrixSpace> P_x_x_L_space_;
    00386
    00388     SmartPtr<ExpansionMatrix> P_x_x_U_;
    00389     SmartPtr<ExpansionMatrixSpace> P_x_x_U_space_;
    00390
    00392     SmartPtr<ExpansionMatrixSpace> P_c_g_space_;
    00393     SmartPtr<ExpansionMatrix> P_c_g_;
    00394
    00396     SmartPtr<ExpansionMatrixSpace> P_d_g_space_;
    00397     SmartPtr<ExpansionMatrix> P_d_g_;
    00398
    00399     Index* jac_idx_map_;
    00400     Index* h_idx_map_;
    00401
    00403     Index* x_fixed_map_;
    00405
    00409     Index findiff_jac_nnz_;
    00412     Index* findiff_jac_ia_;
    00415     Index* findiff_jac_ja_;
    00417     Index* findiff_jac_postriplet_;
    00419     Number* findiff_x_l_;
    00421     Number* findiff_x_u_;
    00423   };
    00424
    00425 } // namespace Ipopt
    00426
    00427 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines