- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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

Go to the documentation of this file.

    00001 // Copyright (C) 2005, 2007 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: MittelmannBndryCntrlDiri3D.hpp 1324 2008-09-16 14:19:26Z andreasw $
    00006 //
    00007 // Authors:  Andreas Waechter             IBM    2005-10-18
    00008 //           Olaf Schenk   (Univ. of Basel)      2007-08-01
    00009 //              modified MittelmannBndryCntrlDiri.hpp for 3-dim problem
    00010
    00011 #ifndef __MITTELMANNBNDRYCNTRLDIRI3D_HPP__
    00012 #define __MITTELMANNBNDRYCNTRLDIRI3D_HPP__
    00013
    00014 #include "RegisteredTNLP.hpp"
    00015
    00016 #ifdef HAVE_CMATH
    00017 # include <cmath>
    00018 #else
    00019 # ifdef HAVE_MATH_H
    00020 #  include <math.h>
    00021 # else
    00022 #  error "don't have header file for math"
    00023 # endif
    00024 #endif
    00025
    00026 using namespace Ipopt;
    00027
    00037 class MittelmannBndryCntrlDiriBase3D : public RegisteredTNLP
    00038 {
    00039 public:
    00041   MittelmannBndryCntrlDiriBase3D();
    00042
    00044   virtual ~MittelmannBndryCntrlDiriBase3D();
    00045
    00049   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
    00050                             Index& nnz_h_lag, IndexStyleEnum& index_style);
    00051
    00053   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
    00054                                Index m, Number* g_l, Number* g_u);
    00055
    00057   virtual bool get_starting_point(Index n, bool init_x, Number* x,
    00058                                   bool init_z, Number* z_L, Number* z_U,
    00059                                   Index m, bool init_lambda,
    00060                                   Number* lambda);
    00061
    00063   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
    00064
    00066   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
    00067
    00069   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
    00070
    00075   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
    00076                           Index m, Index nele_jac, Index* iRow, Index *jCol,
    00077                           Number* values);
    00078
    00083   virtual bool eval_h(Index n, const Number* x, bool new_x,
    00084                       Number obj_factor, Index m, const Number* lambda,
    00085                       bool new_lambda, Index nele_hess, Index* iRow,
    00086                       Index* jCol, Number* values);
    00087
    00089
    00091   virtual bool get_scaling_parameters(Number& obj_scaling,
    00092                                       bool& use_x_scaling, Index n,
    00093                                       Number* x_scaling,
    00094                                       bool& use_g_scaling, Index m,
    00095                                       Number* g_scaling);
    00096
    00101   virtual void finalize_solution(SolverReturn status,
    00102                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
    00103                                  Index m, const Number* g, const Number* lambda,
    00104                                  Number obj_valu,
    00105                                  const IpoptData* ip_data,
    00106                                  IpoptCalculatedQuantities* ip_cq);
    00108
    00109 protected:
    00113   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00114                          Number ub_y, Number lb_u, Number ub_u,
    00115                          Number d_const, Number B, Number C);
    00116
    00120   virtual Number y_d_cont(Number x1, Number x2, Number x3) const =0;
    00122
    00123 private:
    00135   MittelmannBndryCntrlDiriBase3D(const MittelmannBndryCntrlDiriBase3D&);
    00136   MittelmannBndryCntrlDiriBase3D& operator=(const MittelmannBndryCntrlDiriBase3D&);
    00138
    00142   Index N_;
    00144   Number h_;
    00146   Number hh_;
    00148   Number hhh_;
    00150   Number lb_y_;
    00152   Number ub_y_;
    00154   Number lb_u_;
    00156   Number ub_u_;
    00158   Number d_const_;
    00161   Number alpha_;
    00163   Number* y_d_;
    00165
    00170   inline Index y_index(Index i, Index j, Index k) const
    00171   {
    00172     return k + (N_+2)*j + (N_+2)*(N_+2)*i;
    00173   }
    00176   inline Index pde_index(Index i, Index j, Index k) const
    00177   {
    00178     return (k-1) + N_*(j-1) + N_*N_*(i-1);
    00179   }
    00181   inline Number x1_grid(Index i) const
    00182   {
    00183     return h_*(Number)i;
    00184   }
    00186   inline Number x2_grid(Index i) const
    00187   {
    00188     return h_*(Number)i;
    00189   }
    00191   inline Number x3_grid(Index i) const
    00192   {
    00193     return h_*(Number)i;
    00194   }
    00196   inline Number PenObj(Number t) const
    00197   {
    00198     //return 0.5*t*t;
    00199     if (t > B_) {
    00200       return B_*B_/2. + C_*(t - B_);
    00201     }
    00202     else if (t < -B_) {
    00203       return B_*B_/2. + C_*(-t - B_);
    00204     }
    00205     else {
    00206       const Number t2 = t*t;
    00207       const Number t4 = t2*t2;
    00208       const Number t6 = t4*t2;
    00209       return PenA_*t2 + PenB_*t4 + PenC_*t6;
    00210     }
    00211   }
    00213   inline Number PenObj_1(Number t) const
    00214   {
    00215     //return t;
    00216     if (t > B_) {
    00217       return C_;
    00218     }
    00219     else if (t < -B_) {
    00220       return -C_;
    00221     }
    00222     else {
    00223       const Number t2 = t*t;
    00224       const Number t3 = t*t2;
    00225       const Number t5 = t3*t2;
    00226       return 2.*PenA_*t + 4.*PenB_*t3 + 6.*PenC_*t5;
    00227     }
    00228   }
    00230   inline Number PenObj_2(Number t) const
    00231   {
    00232     //return 1.;
    00233     if (t > B_) {
    00234       return 0.;
    00235     }
    00236     else if (t < -B_) {
    00237       return 0.;
    00238     }
    00239     else {
    00240       const Number t2 = t*t;
    00241       const Number t4 = t2*t2;
    00242       return 2.*PenA_ + 12.*PenB_*t2 + 30.*PenC_*t4;
    00243     }
    00244   }
    00246
    00249   Number B_;
    00250   Number C_;
    00251   Number PenA_;
    00252   Number PenB_;
    00253   Number PenC_;
    00255 };
    00256
    00258 class MittelmannBndryCntrlDiri3D : public MittelmannBndryCntrlDiriBase3D
    00259 {
    00260 public:
    00261   MittelmannBndryCntrlDiri3D()
    00262   {}
    00263
    00264   virtual ~MittelmannBndryCntrlDiri3D()
    00265   {}
    00266
    00267   virtual bool InitializeProblem(Index N)
    00268   {
    00269     if (N<1) {
    00270       printf("N has to be at least 1.");
    00271       return false;
    00272     }
    00273     Number alpha = 0.01;
    00274     Number lb_y = -1e20;
    00275     Number ub_y = 3.5;
    00276     Number lb_u = 0.;
    00277     Number ub_u = 10.;
    00278     Number d_const = -20.;
    00279     Number B = .5;
    00280     Number C = 0.01;
    00281     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, d_const, B, C);
    00282     return true;
    00283   }
    00284 protected:
    00286   virtual Number y_d_cont(Number x1, Number x2, Number x3)  const
    00287   {
    00288     return 3. + 5.*(x1*(x1-1.)*x2*(x2-1.));
    00289   }
    00290 private:
    00293   MittelmannBndryCntrlDiri3D(const MittelmannBndryCntrlDiri3D&);
    00294   MittelmannBndryCntrlDiri3D& operator=(const MittelmannBndryCntrlDiri3D&);
    00296
    00297 };
    00298
    00299
    00300 #endif