- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.2.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 759 2006-07-07 03:07:08Z 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_value);
    00105
    00106 protected:
    00110   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00111                          Number ub_y, Number lb_u, Number ub_u,
    00112                          Number d_const);
    00113
    00117   virtual Number y_d_cont(Number x1, Number x2) const =0;
    00119
    00120 private:
    00132   MittelmannBndryCntrlDiriBase(const MittelmannBndryCntrlDiriBase&);
    00133   MittelmannBndryCntrlDiriBase& operator=(const MittelmannBndryCntrlDiriBase&);
    00135
    00139   Index N_;
    00141   Number h_;
    00143   Number hh_;
    00145   Number lb_y_;
    00147   Number ub_y_;
    00149   Number lb_u_;
    00151   Number ub_u_;
    00153   Number d_const_;
    00156   Number alpha_;
    00158   Number* y_d_;
    00160
    00165   inline Index y_index(Index i, Index j) const
    00166   {
    00167     return j + (N_+2)*i;
    00168   }
    00171   inline Index pde_index(Index i, Index j) const
    00172   {
    00173     return (j-1) + N_*(i-1);
    00174   }
    00176   inline Number x1_grid(Index i) const
    00177   {
    00178     return h_*(Number)i;
    00179   }
    00181   inline Number x2_grid(Index i) const
    00182   {
    00183     return h_*(Number)i;
    00184   }
    00186 };
    00187
    00189 class MittelmannBndryCntrlDiri1 : public MittelmannBndryCntrlDiriBase
    00190 {
    00191 public:
    00192   MittelmannBndryCntrlDiri1()
    00193   {}
    00194
    00195   virtual ~MittelmannBndryCntrlDiri1()
    00196   {}
    00197
    00198   virtual bool InitializeProblem(Index N)
    00199   {
    00200     if (N<1) {
    00201       printf("N has to be at least 1.");
    00202       return false;
    00203     }
    00204     Number alpha = 0.01;
    00205     Number lb_y = -1e20;
    00206     Number ub_y = 3.5;
    00207     Number lb_u = 0.;
    00208     Number ub_u = 10.;
    00209     Number d_const = -20.;
    00210     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00211     return true;
    00212   }
    00213 protected:
    00215   virtual Number y_d_cont(Number x1, Number x2)  const
    00216   {
    00217     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00218   }
    00219 private:
    00222   MittelmannBndryCntrlDiri1(const MittelmannBndryCntrlDiri1&);
    00223   MittelmannBndryCntrlDiri1& operator=(const MittelmannBndryCntrlDiri1&);
    00225 };
    00226
    00228 class MittelmannBndryCntrlDiri2 : public MittelmannBndryCntrlDiriBase
    00229 {
    00230 public:
    00231   MittelmannBndryCntrlDiri2()
    00232   {}
    00233
    00234   virtual ~MittelmannBndryCntrlDiri2()
    00235   {}
    00236
    00237   virtual bool InitializeProblem(Index N)
    00238   {
    00239     if (N<1) {
    00240       printf("N has to be at least 1.");
    00241       return false;
    00242     }
    00243     Number alpha = 0.;
    00244     Number lb_y = -1e20;
    00245     Number ub_y = 3.5;
    00246     Number lb_u = 0.;
    00247     Number ub_u = 10.;
    00248     Number d_const = -20.;
    00249     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00250     return true;
    00251   }
    00252 protected:
    00254   virtual Number y_d_cont(Number x1, Number x2)  const
    00255   {
    00256     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00257   }
    00258 private:
    00261   MittelmannBndryCntrlDiri2(const MittelmannBndryCntrlDiri2&);
    00262   MittelmannBndryCntrlDiri2& operator=(const MittelmannBndryCntrlDiri2&);
    00264 };
    00265
    00267 class MittelmannBndryCntrlDiri3 : public MittelmannBndryCntrlDiriBase
    00268 {
    00269 public:
    00270   MittelmannBndryCntrlDiri3()
    00271   {}
    00272
    00273   virtual ~MittelmannBndryCntrlDiri3()
    00274   {}
    00275
    00276   virtual bool InitializeProblem(Index N)
    00277   {
    00278     if (N<1) {
    00279       printf("N has to be at least 1.");
    00280       return false;
    00281     }
    00282     Number alpha = 0.01;
    00283     Number lb_y = -1e20;
    00284     Number ub_y = 3.2;
    00285     Number lb_u = 1.6;
    00286     Number ub_u = 2.3;
    00287     Number d_const = -20.;
    00288     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00289     return true;
    00290   }
    00291 protected:
    00293   virtual Number y_d_cont(Number x1, Number x2)  const
    00294   {
    00295     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00296   }
    00297 private:
    00300   MittelmannBndryCntrlDiri3(const MittelmannBndryCntrlDiri3&);
    00301   MittelmannBndryCntrlDiri3& operator=(const MittelmannBndryCntrlDiri3&);
    00303 };
    00304
    00306 class MittelmannBndryCntrlDiri4 : public MittelmannBndryCntrlDiriBase
    00307 {
    00308 public:
    00309   MittelmannBndryCntrlDiri4()
    00310   {}
    00311
    00312   virtual ~MittelmannBndryCntrlDiri4()
    00313   {}
    00314
    00315   virtual bool InitializeProblem(Index N)
    00316   {
    00317     if (N<1) {
    00318       printf("N has to be at least 1.");
    00319       return false;
    00320     }
    00321     Number alpha = 0.;
    00322     Number lb_y = -1e20;
    00323     Number ub_y = 3.2;
    00324     Number lb_u = 1.6;
    00325     Number ub_u = 2.3;
    00326     Number d_const = -20.;
    00327     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00328     return true;
    00329   }
    00330 protected:
    00332   virtual Number y_d_cont(Number x1, Number x2)  const
    00333   {
    00334     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00335   }
    00336 private:
    00339   MittelmannBndryCntrlDiri4(const MittelmannBndryCntrlDiri4&);
    00340   MittelmannBndryCntrlDiri4& operator=(const MittelmannBndryCntrlDiri4&);
    00342 };
    00343
    00344 #endif