- Main Page
- Classes
- Files

- File List
- File Members

# examples/ScalableProblems/MittelmannDistCntrlDiri.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 Eclipse Public License.
    00004 //
    00005 // $Id: MittelmannDistCntrlDiri.hpp 2005 2011-06-06 12:55:16Z stefan $
    00006 //
    00007 // Authors:  Andreas Waechter           IBM    2005-10-18
    00008 //                  based on MyNLP.hpp
    00009
    00010 #ifndef __MITTELMANNDISTRCNTRLDIRI_HPP__
    00011 #define __MITTELMANNDISTRCNTRLDIRI_HPP__
    00012
    00013 #include "IpTNLP.hpp"
    00014 #include "RegisteredTNLP.hpp"
    00015
    00016 #ifdef HAVE_CONFIG_H
    00017 #include "config.h"
    00018 #else
    00019 #include "configall_system.h"
    00020 #endif
    00021
    00022 #ifdef HAVE_CMATH
    00023 # include <cmath>
    00024 #else
    00025 # ifdef HAVE_MATH_H
    00026 #  include <math.h>
    00027 # else
    00028 #  error "don't have header file for math"
    00029 # endif
    00030 #endif
    00031
    00032 #ifdef HAVE_CSTDIO
    00033 # include <cstdio>
    00034 #else
    00035 # ifdef HAVE_STDIO_H
    00036 #  include <stdio.h>
    00037 # else
    00038 #  error "don't have header file for stdio"
    00039 # endif
    00040 #endif
    00041
    00042 using namespace Ipopt;
    00043
    00050 class MittelmannDistCntrlDiriBase : public RegisteredTNLP
    00051 {
    00052 public:
    00055   MittelmannDistCntrlDiriBase();
    00056
    00058   virtual ~MittelmannDistCntrlDiriBase();
    00059
    00063   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
    00064                             Index& nnz_h_lag, IndexStyleEnum& index_style);
    00065
    00067   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
    00068                                Index m, Number* g_l, Number* g_u);
    00069
    00071   virtual bool get_starting_point(Index n, bool init_x, Number* x,
    00072                                   bool init_z, Number* z_L, Number* z_U,
    00073                                   Index m, bool init_lambda,
    00074                                   Number* lambda);
    00075
    00077   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
    00078
    00080   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
    00081
    00083   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
    00084
    00089   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
    00090                           Index m, Index nele_jac, Index* iRow, Index *jCol,
    00091                           Number* values);
    00092
    00097   virtual bool eval_h(Index n, const Number* x, bool new_x,
    00098                       Number obj_factor, Index m, const Number* lambda,
    00099                       bool new_lambda, Index nele_hess, Index* iRow,
    00100                       Index* jCol, Number* values);
    00101
    00103
    00105   virtual bool get_scaling_parameters(Number& obj_scaling,
    00106                                       bool& use_x_scaling, Index n,
    00107                                       Number* x_scaling,
    00108                                       bool& use_g_scaling, Index m,
    00109                                       Number* g_scaling);
    00110
    00115   virtual void finalize_solution(SolverReturn status,
    00116                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
    00117                                  Index m, const Number* g, const Number* lambda,
    00118                                  Number obj_value,
    00119                  const IpoptData* ip_data,
    00120                  IpoptCalculatedQuantities* ip_cq);
    00122
    00123 protected:
    00127   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00128                          Number ub_y, Number lb_u, Number ub_u,
    00129                          Number u_init);
    00130
    00134   virtual Number y_d_cont(Number x1, Number x2) const =0;
    00136   virtual Number d_cont(Number x1, Number x2, Number y, Number u) const =0;
    00138   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const =0;
    00140   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const =0;
    00142   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const =0;
    00144
    00145 private:
    00157   MittelmannDistCntrlDiriBase(const MittelmannDistCntrlDiriBase&);
    00158   MittelmannDistCntrlDiriBase& operator=(const MittelmannDistCntrlDiriBase&);
    00160
    00164   Index N_;
    00166   Number h_;
    00168   Number hh_;
    00170   Number lb_y_;
    00172   Number ub_y_;
    00174   Number lb_u_;
    00176   Number ub_u_;
    00178   Number u_init_;
    00181   Number alpha_;
    00183   Number* y_d_;
    00185
    00190   inline Index y_index(Index i, Index j) const
    00191   {
    00192     return j + (N_+2)*i;
    00193   }
    00196   inline Index u_index(Index i, Index j) const
    00197   {
    00198     return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1);
    00199   }
    00202   inline Index pde_index(Index i, Index j) const
    00203   {
    00204     return (j-1) + N_*(i-1);
    00205   }
    00207   inline Number x1_grid(Index i) const
    00208   {
    00209     return h_*(Number)i;
    00210   }
    00212   inline Number x2_grid(Index i) const
    00213   {
    00214     return h_*(Number)i;
    00215   }
    00217 };
    00218
    00220 class MittelmannDistCntrlDiri1 : public MittelmannDistCntrlDiriBase
    00221 {
    00222 public:
    00223   MittelmannDistCntrlDiri1()
    00224   {}
    00225
    00226   virtual ~MittelmannDistCntrlDiri1()
    00227   {}
    00228
    00229   virtual bool InitializeProblem(Index N)
    00230   {
    00231     if (N<1) {
    00232       printf("N has to be at least 1.");
    00233       return false;
    00234     }
    00235     Number alpha = 0.001;
    00236     Number lb_y = -1e20;
    00237     Number ub_y = 0.185;
    00238     Number lb_u = 1.5;
    00239     Number ub_u = 4.5;
    00240     Number u_init = (ub_u+lb_u)/2.;
    00241
    00242     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00243     return true;
    00244   }
    00245 protected:
    00247   virtual Number y_d_cont(Number x1, Number x2)  const
    00248   {
    00249     return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
    00250   }
    00252   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00253   {
    00254     return pow(y,3) - y - u;
    00255   }
    00257   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00258   {
    00259     return 3.*y*y - 1.;
    00260   }
    00262   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00263   {
    00264     return -1.;
    00265   }
    00267   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00268   {
    00269     return 6.*y;
    00270   }
    00271 private:
    00274   MittelmannDistCntrlDiri1(const MittelmannDistCntrlDiri1&);
    00275   MittelmannDistCntrlDiri1& operator=(const MittelmannDistCntrlDiri1&);
    00277 };
    00278
    00280 class MittelmannDistCntrlDiri2 : public MittelmannDistCntrlDiriBase
    00281 {
    00282 public:
    00283   MittelmannDistCntrlDiri2()
    00284   {}
    00285   virtual ~MittelmannDistCntrlDiri2()
    00286   {}
    00287   virtual bool InitializeProblem(Index N)
    00288   {
    00289     if (N<1) {
    00290       printf("N has to be at least 1.");
    00291       return false;
    00292     }
    00293     Number alpha = 0.;
    00294     Number lb_y = -1e20;
    00295     Number ub_y = 0.185;
    00296     Number lb_u = 1.5;
    00297     Number ub_u = 4.5;
    00298     Number u_init = (ub_u+lb_u)/2.;
    00299
    00300     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00301     return true;
    00302   }
    00303 protected:
    00305   virtual Number y_d_cont(Number x1, Number x2)  const
    00306   {
    00307     return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
    00308   }
    00310   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00311   {
    00312     return pow(y,3) - y - u;
    00313   }
    00315   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00316   {
    00317     return 3.*y*y - 1.;
    00318   }
    00320   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00321   {
    00322     return -1.;
    00323   }
    00325   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00326   {
    00327     return 6.*y;
    00328   }
    00329 private:
    00332   MittelmannDistCntrlDiri2(const MittelmannDistCntrlDiri2&);
    00333   MittelmannDistCntrlDiri2& operator=(const MittelmannDistCntrlDiri2&);
    00335 };
    00336
    00338 class MittelmannDistCntrlDiri3 : public MittelmannDistCntrlDiriBase
    00339 {
    00340 public:
    00341   MittelmannDistCntrlDiri3()
    00342       :
    00343       pi_(4.*atan(1.))
    00344   {}
    00345   virtual ~MittelmannDistCntrlDiri3()
    00346   {}
    00347   virtual bool InitializeProblem(Index N)
    00348   {
    00349     if (N<1) {
    00350       printf("N has to be at least 1.");
    00351       return false;
    00352     }
    00353     Number alpha = 0.001;
    00354     Number lb_y = -1e20;
    00355     Number ub_y = 0.11;
    00356     Number lb_u = -5;
    00357     Number ub_u = 5.;
    00358     Number u_init = (ub_u+lb_u)/2.;
    00359
    00360     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00361     return true;
    00362   }
    00363 protected:
    00365   virtual Number y_d_cont(Number x1, Number x2)  const
    00366   {
    00367     return sin(2.*pi_*x1)*sin(2.*pi_*x2);
    00368   }
    00370   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00371   {
    00372     return -exp(y) - u;
    00373   }
    00375   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00376   {
    00377     return -exp(y);
    00378   }
    00380   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00381   {
    00382     return -1.;
    00383   }
    00385   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00386   {
    00387     return -exp(y);
    00388   }
    00389 private:
    00392   MittelmannDistCntrlDiri3(const MittelmannDistCntrlDiri3&);
    00393   MittelmannDistCntrlDiri3& operator=(const MittelmannDistCntrlDiri3&);
    00395
    00396   const Number pi_;
    00397 };
    00398
    00399 class MittelmannDistCntrlDiri3a : public MittelmannDistCntrlDiriBase
    00400 {
    00401 public:
    00402   MittelmannDistCntrlDiri3a()
    00403       :
    00404       pi_(4.*atan(1.))
    00405   {}
    00406   virtual ~MittelmannDistCntrlDiri3a()
    00407   {}
    00408   virtual bool InitializeProblem(Index N)
    00409   {
    00410     if (N<1) {
    00411       printf("N has to be at least 1.");
    00412       return false;
    00413     }
    00414     Number alpha = 0.;
    00415     Number lb_y = -1e20;
    00416     Number ub_y = 0.11;
    00417     Number lb_u = -5;
    00418     Number ub_u = 5.;
    00419     Number u_init = (ub_u+lb_u)/2.;
    00420
    00421     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00422     return true;
    00423   }
    00424 protected:
    00426   virtual Number y_d_cont(Number x1, Number x2)  const
    00427   {
    00428     return sin(2.*pi_*x1)*sin(2.*pi_*x2);
    00429   }
    00431   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00432   {
    00433     return -exp(y) - u;
    00434   }
    00436   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00437   {
    00438     return -exp(y);
    00439   }
    00441   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00442   {
    00443     return -1.;
    00444   }
    00446   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00447   {
    00448     return -exp(y);
    00449   }
    00450 private:
    00453   MittelmannDistCntrlDiri3a(const MittelmannDistCntrlDiri3a&);
    00454   MittelmannDistCntrlDiri3a& operator=(const MittelmannDistCntrlDiri3a&);
    00456
    00457   const Number pi_;
    00458 };
    00459
    00460 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines