- Main Page
- Classes
- Files

- File List
- File Members

# 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 Eclipse Public License.
    00004 //
    00005 // $Id: MittelmannBndryCntrlDiri.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 __MITTELMANNBNDRYCNTRLDIRI_HPP__
    00011 #define __MITTELMANNBNDRYCNTRLDIRI_HPP__
    00012
    00013 #include "RegisteredTNLP.hpp"
    00014
    00015 #ifdef HAVE_CONFIG_H
    00016 #include "config.h"
    00017 #else
    00018 #include "configall_system.h"
    00019 #endif
    00020
    00021 #ifdef HAVE_CMATH
    00022 # include <cmath>
    00023 #else
    00024 # ifdef HAVE_MATH_H
    00025 #  include <math.h>
    00026 # else
    00027 #  error "don't have header file for math"
    00028 # endif
    00029 #endif
    00030
    00031 #ifdef HAVE_CSTDIO
    00032 # include <cstdio>
    00033 #else
    00034 # ifdef HAVE_STDIO_H
    00035 #  include <stdio.h>
    00036 # else
    00037 #  error "don't have header file for stdio"
    00038 # endif
    00039 #endif
    00040
    00041 using namespace Ipopt;
    00042
    00052 class MittelmannBndryCntrlDiriBase : public RegisteredTNLP
    00053 {
    00054 public:
    00056   MittelmannBndryCntrlDiriBase();
    00057
    00059   virtual ~MittelmannBndryCntrlDiriBase();
    00060
    00064   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
    00065                             Index& nnz_h_lag, IndexStyleEnum& index_style);
    00066
    00068   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
    00069                                Index m, Number* g_l, Number* g_u);
    00070
    00072   virtual bool get_starting_point(Index n, bool init_x, Number* x,
    00073                                   bool init_z, Number* z_L, Number* z_U,
    00074                                   Index m, bool init_lambda,
    00075                                   Number* lambda);
    00076
    00078   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
    00079
    00081   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
    00082
    00084   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
    00085
    00090   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
    00091                           Index m, Index nele_jac, Index* iRow, Index *jCol,
    00092                           Number* values);
    00093
    00098   virtual bool eval_h(Index n, const Number* x, bool new_x,
    00099                       Number obj_factor, Index m, const Number* lambda,
    00100                       bool new_lambda, Index nele_hess, Index* iRow,
    00101                       Index* jCol, Number* values);
    00102
    00104
    00106   virtual bool get_scaling_parameters(Number& obj_scaling,
    00107                                       bool& use_x_scaling, Index n,
    00108                                       Number* x_scaling,
    00109                                       bool& use_g_scaling, Index m,
    00110                                       Number* g_scaling);
    00111
    00116   virtual void finalize_solution(SolverReturn status,
    00117                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
    00118                                  Index m, const Number* g, const Number* lambda,
    00119                                  Number obj_valu,
    00120                  const IpoptData* ip_data,
    00121                  IpoptCalculatedQuantities* ip_cq);
    00123
    00124 protected:
    00128   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00129                          Number ub_y, Number lb_u, Number ub_u,
    00130                          Number d_const);
    00131
    00135   virtual Number y_d_cont(Number x1, Number x2) const =0;
    00137
    00138 private:
    00150   MittelmannBndryCntrlDiriBase(const MittelmannBndryCntrlDiriBase&);
    00151   MittelmannBndryCntrlDiriBase& operator=(const MittelmannBndryCntrlDiriBase&);
    00153
    00157   Index N_;
    00159   Number h_;
    00161   Number hh_;
    00163   Number lb_y_;
    00165   Number ub_y_;
    00167   Number lb_u_;
    00169   Number ub_u_;
    00171   Number d_const_;
    00174   Number alpha_;
    00176   Number* y_d_;
    00178
    00183   inline Index y_index(Index i, Index j) const
    00184   {
    00185     return j + (N_+2)*i;
    00186   }
    00189   inline Index pde_index(Index i, Index j) const
    00190   {
    00191     return (j-1) + N_*(i-1);
    00192   }
    00194   inline Number x1_grid(Index i) const
    00195   {
    00196     return h_*(Number)i;
    00197   }
    00199   inline Number x2_grid(Index i) const
    00200   {
    00201     return h_*(Number)i;
    00202   }
    00204 };
    00205
    00207 class MittelmannBndryCntrlDiri1 : public MittelmannBndryCntrlDiriBase
    00208 {
    00209 public:
    00210   MittelmannBndryCntrlDiri1()
    00211   {}
    00212
    00213   virtual ~MittelmannBndryCntrlDiri1()
    00214   {}
    00215
    00216   virtual bool InitializeProblem(Index N)
    00217   {
    00218     if (N<1) {
    00219       printf("N has to be at least 1.");
    00220       return false;
    00221     }
    00222     Number alpha = 0.01;
    00223     Number lb_y = -1e20;
    00224     Number ub_y = 3.5;
    00225     Number lb_u = 0.;
    00226     Number ub_u = 10.;
    00227     Number d_const = -20.;
    00228     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00229     return true;
    00230   }
    00231 protected:
    00233   virtual Number y_d_cont(Number x1, Number x2)  const
    00234   {
    00235     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00236   }
    00237 private:
    00240   MittelmannBndryCntrlDiri1(const MittelmannBndryCntrlDiri1&);
    00241   MittelmannBndryCntrlDiri1& operator=(const MittelmannBndryCntrlDiri1&);
    00243 };
    00244
    00246 class MittelmannBndryCntrlDiri2 : public MittelmannBndryCntrlDiriBase
    00247 {
    00248 public:
    00249   MittelmannBndryCntrlDiri2()
    00250   {}
    00251
    00252   virtual ~MittelmannBndryCntrlDiri2()
    00253   {}
    00254
    00255   virtual bool InitializeProblem(Index N)
    00256   {
    00257     if (N<1) {
    00258       printf("N has to be at least 1.");
    00259       return false;
    00260     }
    00261     Number alpha = 0.;
    00262     Number lb_y = -1e20;
    00263     Number ub_y = 3.5;
    00264     Number lb_u = 0.;
    00265     Number ub_u = 10.;
    00266     Number d_const = -20.;
    00267     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00268     return true;
    00269   }
    00270 protected:
    00272   virtual Number y_d_cont(Number x1, Number x2)  const
    00273   {
    00274     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00275   }
    00276 private:
    00279   MittelmannBndryCntrlDiri2(const MittelmannBndryCntrlDiri2&);
    00280   MittelmannBndryCntrlDiri2& operator=(const MittelmannBndryCntrlDiri2&);
    00282 };
    00283
    00285 class MittelmannBndryCntrlDiri3 : public MittelmannBndryCntrlDiriBase
    00286 {
    00287 public:
    00288   MittelmannBndryCntrlDiri3()
    00289   {}
    00290
    00291   virtual ~MittelmannBndryCntrlDiri3()
    00292   {}
    00293
    00294   virtual bool InitializeProblem(Index N)
    00295   {
    00296     if (N<1) {
    00297       printf("N has to be at least 1.");
    00298       return false;
    00299     }
    00300     Number alpha = 0.01;
    00301     Number lb_y = -1e20;
    00302     Number ub_y = 3.2;
    00303     Number lb_u = 1.6;
    00304     Number ub_u = 2.3;
    00305     Number d_const = -20.;
    00306     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00307     return true;
    00308   }
    00309 protected:
    00311   virtual Number y_d_cont(Number x1, Number x2)  const
    00312   {
    00313     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00314   }
    00315 private:
    00318   MittelmannBndryCntrlDiri3(const MittelmannBndryCntrlDiri3&);
    00319   MittelmannBndryCntrlDiri3& operator=(const MittelmannBndryCntrlDiri3&);
    00321 };
    00322
    00324 class MittelmannBndryCntrlDiri4 : public MittelmannBndryCntrlDiriBase
    00325 {
    00326 public:
    00327   MittelmannBndryCntrlDiri4()
    00328   {}
    00329
    00330   virtual ~MittelmannBndryCntrlDiri4()
    00331   {}
    00332
    00333   virtual bool InitializeProblem(Index N)
    00334   {
    00335     if (N<1) {
    00336       printf("N has to be at least 1.");
    00337       return false;
    00338     }
    00339     Number alpha = 0.;
    00340     Number lb_y = -1e20;
    00341     Number ub_y = 3.2;
    00342     Number lb_u = 1.6;
    00343     Number ub_u = 2.3;
    00344     Number d_const = -20.;
    00345     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const);
    00346     return true;
    00347   }
    00348 protected:
    00350   virtual Number y_d_cont(Number x1, Number x2)  const
    00351   {
    00352     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00353   }
    00354 private:
    00357   MittelmannBndryCntrlDiri4(const MittelmannBndryCntrlDiri4&);
    00358   MittelmannBndryCntrlDiri4& operator=(const MittelmannBndryCntrlDiri4&);
    00360 };
    00361
    00362 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines