- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.7.1/Ipopt/examples/ScalableProblems/MittelmannBndryCntrlDiri.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2005, 2006 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: MittelmannBndryCntrlDiri.hpp 1324 2008-09-16 14:19:26Z andreasw $
    00006 //
    00007 // Authors:  Andreas Waechter           IBM    2005-10-18
    00008 //                  based on MyNLP.hpp
    00009
    00010 #ifndef __MITTELMANNBNDRYCNTRLDIRI_HPP__
    00011 #define __MITTELMANNBNDRYCNTRLDIRI_HPP__
    00012
    00013 #include "RegisteredTNLP.hpp"
    00014
    00015 #ifdef HAVE_CMATH
    00016 # include <cmath>
    00017 #else
    00018 # ifdef HAVE_MATH_H
    00019 #  include <math.h>
    00020 # else
    00021 #  error "don't have header file for math"
    00022 # endif
    00023 #endif
    00024
    00025 using namespace Ipopt;
    00026
    00036 class MittelmannBndryCntrlDiriBase : public RegisteredTNLP
    00037 {
    00038 public:
    00040   MittelmannBndryCntrlDiriBase();
    00041
    00043   virtual ~MittelmannBndryCntrlDiriBase();
    00044
    00048   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
    00049                             Index& nnz_h_lag, IndexStyleEnum& index_style);
    00050
    00052   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
    00053                                Index m, Number* g_l, Number* g_u);
    00054
    00056   virtual bool get_starting_point(Index n, bool init_x, Number* x,
    00057                                   bool init_z, Number* z_L, Number* z_U,
    00058                                   Index m, bool init_lambda,
    00059                                   Number* lambda);
    00060
    00062   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
    00063
    00065   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
    00066
    00068   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
    00069
    00074   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
    00075                           Index m, Index nele_jac, Index* iRow, Index *jCol,
    00076                           Number* values);
    00077
    00082   virtual bool eval_h(Index n, const Number* x, bool new_x,
    00083                       Number obj_factor, Index m, const Number* lambda,
    00084                       bool new_lambda, Index nele_hess, Index* iRow,
    00085                       Index* jCol, Number* values);
    00086
    00088
    00090   virtual bool get_scaling_parameters(Number& obj_scaling,
    00091                                       bool& use_x_scaling, Index n,
    00092                                       Number* x_scaling,
    00093                                       bool& use_g_scaling, Index m,
    00094                                       Number* g_scaling);
    00095
    00100   virtual void finalize_solution(SolverReturn status,
    00101                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
    00102                                  Index m, const Number* g, const Number* lambda,
    00103                                  Number obj_valu,
    00104                                  const IpoptData* ip_data,
    00105                                  IpoptCalculatedQuantities* ip_cq);
    00107
    00108 protected:
    00112   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00113                          Number ub_y, Number lb_u, Number ub_u,
    00114                          Number d_const);
    00115
    00119   virtual Number y_d_cont(Number x1, Number x2) const =0;
    00121
    00122 private:
    00134   MittelmannBndryCntrlDiriBase(const MittelmannBndryCntrlDiriBase&);
    00135   MittelmannBndryCntrlDiriBase& operator=(const MittelmannBndryCntrlDiriBase&);
    00137
    00141   Index N_;
    00143   Number h_;
    00145   Number hh_;
    00147   Number lb_y_;
    00149   Number ub_y_;
    00151   Number lb_u_;
    00153   Number ub_u_;
    00155   Number d_const_;
    00158   Number alpha_;
    00160   Number* y_d_;
    00162
    00167   inline Index y_index(Index i, Index j) const
    00168   {
    00169     return j + (N_+2)*i;
    00170   }
    00173   inline Index pde_index(Index i, Index j) const
    00174   {
    00175     return (j-1) + N_*(i-1);
    00176   }
    00178   inline Number x1_grid(Index i) const
    00179   {
    00180     return h_*(Number)i;
    00181   }
    00183   inline Number x2_grid(Index i) const
    00184   {
    00185     return h_*(Number)i;
    00186   }
    00188 };
    00189
    00191 class MittelmannBndryCntrlDiri1 : public MittelmannBndryCntrlDiriBase
    00192 {
    00193 public:
    00194   MittelmannBndryCntrlDiri1()
    00195   {}
    00196
    00197   virtual ~MittelmannBndryCntrlDiri1()
    00198   {}
    00199
    00200   virtual bool InitializeProblem(Index N)
    00201   {
    00202     if (N<1) {
    00203       printf("N has to be at least 1.");
    00204       return false;
    00205     }
    00206     Number alpha = 0.01;
    00207     Number lb_y = -1e20;
    00208     Number ub_y = 3.5;
    00209     Number lb_u = 0.;
    00210     Number ub_u = 10.;
    00211     Number d_const = -20.;
    00212     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00213     return true;
    00214   }
    00215 protected:
    00217   virtual Number y_d_cont(Number x1, Number x2)  const
    00218   {
    00219     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00220   }
    00221 private:
    00224   MittelmannBndryCntrlDiri1(const MittelmannBndryCntrlDiri1&);
    00225   MittelmannBndryCntrlDiri1& operator=(const MittelmannBndryCntrlDiri1&);
    00227 };
    00228
    00230 class MittelmannBndryCntrlDiri2 : public MittelmannBndryCntrlDiriBase
    00231 {
    00232 public:
    00233   MittelmannBndryCntrlDiri2()
    00234   {}
    00235
    00236   virtual ~MittelmannBndryCntrlDiri2()
    00237   {}
    00238
    00239   virtual bool InitializeProblem(Index N)
    00240   {
    00241     if (N<1) {
    00242       printf("N has to be at least 1.");
    00243       return false;
    00244     }
    00245     Number alpha = 0.;
    00246     Number lb_y = -1e20;
    00247     Number ub_y = 3.5;
    00248     Number lb_u = 0.;
    00249     Number ub_u = 10.;
    00250     Number d_const = -20.;
    00251     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00252     return true;
    00253   }
    00254 protected:
    00256   virtual Number y_d_cont(Number x1, Number x2)  const
    00257   {
    00258     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00259   }
    00260 private:
    00263   MittelmannBndryCntrlDiri2(const MittelmannBndryCntrlDiri2&);
    00264   MittelmannBndryCntrlDiri2& operator=(const MittelmannBndryCntrlDiri2&);
    00266 };
    00267
    00269 class MittelmannBndryCntrlDiri3 : public MittelmannBndryCntrlDiriBase
    00270 {
    00271 public:
    00272   MittelmannBndryCntrlDiri3()
    00273   {}
    00274
    00275   virtual ~MittelmannBndryCntrlDiri3()
    00276   {}
    00277
    00278   virtual bool InitializeProblem(Index N)
    00279   {
    00280     if (N<1) {
    00281       printf("N has to be at least 1.");
    00282       return false;
    00283     }
    00284     Number alpha = 0.01;
    00285     Number lb_y = -1e20;
    00286     Number ub_y = 3.2;
    00287     Number lb_u = 1.6;
    00288     Number ub_u = 2.3;
    00289     Number d_const = -20.;
    00290     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00291     return true;
    00292   }
    00293 protected:
    00295   virtual Number y_d_cont(Number x1, Number x2)  const
    00296   {
    00297     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00298   }
    00299 private:
    00302   MittelmannBndryCntrlDiri3(const MittelmannBndryCntrlDiri3&);
    00303   MittelmannBndryCntrlDiri3& operator=(const MittelmannBndryCntrlDiri3&);
    00305 };
    00306
    00308 class MittelmannBndryCntrlDiri4 : public MittelmannBndryCntrlDiriBase
    00309 {
    00310 public:
    00311   MittelmannBndryCntrlDiri4()
    00312   {}
    00313
    00314   virtual ~MittelmannBndryCntrlDiri4()
    00315   {}
    00316
    00317   virtual bool InitializeProblem(Index N)
    00318   {
    00319     if (N<1) {
    00320       printf("N has to be at least 1.");
    00321       return false;
    00322     }
    00323     Number alpha = 0.;
    00324     Number lb_y = -1e20;
    00325     Number ub_y = 3.2;
    00326     Number lb_u = 1.6;
    00327     Number ub_u = 2.3;
    00328     Number d_const = -20.;
    00329     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00330     return true;
    00331   }
    00332 protected:
    00334   virtual Number y_d_cont(Number x1, Number x2)  const
    00335   {
    00336     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00337   }
    00338 private:
    00341   MittelmannBndryCntrlDiri4(const MittelmannBndryCntrlDiri4&);
    00342   MittelmannBndryCntrlDiri4& operator=(const MittelmannBndryCntrlDiri4&);
    00344 };
    00345
    00346 #endif