- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.5.1/Ipopt/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 Common Public License.
    00004 //
    00005 // $Id: MittelmannDistCntrlDiri.hpp 949 2007-03-27 00:41:26Z andreasw $
    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_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
    00034 class MittelmannDistCntrlDiriBase : public RegisteredTNLP
    00035 {
    00036 public:
    00039   MittelmannDistCntrlDiriBase();
    00040
    00042   virtual ~MittelmannDistCntrlDiriBase();
    00043
    00047   virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
    00048                             Index& nnz_h_lag, IndexStyleEnum& index_style);
    00049
    00051   virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
    00052                                Index m, Number* g_l, Number* g_u);
    00053
    00055   virtual bool get_starting_point(Index n, bool init_x, Number* x,
    00056                                   bool init_z, Number* z_L, Number* z_U,
    00057                                   Index m, bool init_lambda,
    00058                                   Number* lambda);
    00059
    00061   virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
    00062
    00064   virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
    00065
    00067   virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
    00068
    00073   virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
    00074                           Index m, Index nele_jac, Index* iRow, Index *jCol,
    00075                           Number* values);
    00076
    00081   virtual bool eval_h(Index n, const Number* x, bool new_x,
    00082                       Number obj_factor, Index m, const Number* lambda,
    00083                       bool new_lambda, Index nele_hess, Index* iRow,
    00084                       Index* jCol, Number* values);
    00085
    00087
    00089   virtual bool get_scaling_parameters(Number& obj_scaling,
    00090                                       bool& use_x_scaling, Index n,
    00091                                       Number* x_scaling,
    00092                                       bool& use_g_scaling, Index m,
    00093                                       Number* g_scaling);
    00094
    00099   virtual void finalize_solution(SolverReturn status,
    00100                                  Index n, const Number* x, const Number* z_L, const Number* z_U,
    00101                                  Index m, const Number* g, const Number* lambda,
    00102                                  Number obj_value,
    00103                                  const IpoptData* ip_data,
    00104                                  IpoptCalculatedQuantities* ip_cq);
    00106
    00107 protected:
    00111   void SetBaseParameters(Index N, Number alpha, Number lb_y,
    00112                          Number ub_y, Number lb_u, Number ub_u,
    00113                          Number u_init);
    00114
    00118   virtual Number y_d_cont(Number x1, Number x2) const =0;
    00120   virtual Number d_cont(Number x1, Number x2, Number y, Number u) const =0;
    00122   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const =0;
    00124   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const =0;
    00126   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const =0;
    00128
    00129 private:
    00141   MittelmannDistCntrlDiriBase(const MittelmannDistCntrlDiriBase&);
    00142   MittelmannDistCntrlDiriBase& operator=(const MittelmannDistCntrlDiriBase&);
    00144
    00148   Index N_;
    00150   Number h_;
    00152   Number hh_;
    00154   Number lb_y_;
    00156   Number ub_y_;
    00158   Number lb_u_;
    00160   Number ub_u_;
    00162   Number u_init_;
    00165   Number alpha_;
    00167   Number* y_d_;
    00169
    00174   inline Index y_index(Index i, Index j) const
    00175   {
    00176     return j + (N_+2)*i;
    00177   }
    00180   inline Index u_index(Index i, Index j) const
    00181   {
    00182     return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1);
    00183   }
    00186   inline Index pde_index(Index i, Index j) const
    00187   {
    00188     return (j-1) + N_*(i-1);
    00189   }
    00191   inline Number x1_grid(Index i) const
    00192   {
    00193     return h_*(Number)i;
    00194   }
    00196   inline Number x2_grid(Index i) const
    00197   {
    00198     return h_*(Number)i;
    00199   }
    00201 };
    00202
    00204 class MittelmannDistCntrlDiri1 : public MittelmannDistCntrlDiriBase
    00205 {
    00206 public:
    00207   MittelmannDistCntrlDiri1()
    00208   {}
    00209
    00210   virtual ~MittelmannDistCntrlDiri1()
    00211   {}
    00212
    00213   virtual bool InitializeProblem(Index N)
    00214   {
    00215     if (N<1) {
    00216       printf("N has to be at least 1.");
    00217       return false;
    00218     }
    00219     Number alpha = 0.001;
    00220     Number lb_y = -1e20;
    00221     Number ub_y = 0.185;
    00222     Number lb_u = 1.5;
    00223     Number ub_u = 4.5;
    00224     Number u_init = (ub_u+lb_u)/2.;
    00225
    00226     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00227     return true;
    00228   }
    00229 protected:
    00231   virtual Number y_d_cont(Number x1, Number x2)  const
    00232   {
    00233     return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
    00234   }
    00236   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00237   {
    00238     return pow(y,3) - y - u;
    00239   }
    00241   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00242   {
    00243     return 3.*y*y - 1.;
    00244   }
    00246   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00247   {
    00248     return -1.;
    00249   }
    00251   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00252   {
    00253     return 6.*y;
    00254   }
    00255 private:
    00258   MittelmannDistCntrlDiri1(const MittelmannDistCntrlDiri1&);
    00259   MittelmannDistCntrlDiri1& operator=(const MittelmannDistCntrlDiri1&);
    00261 };
    00262
    00264 class MittelmannDistCntrlDiri2 : public MittelmannDistCntrlDiriBase
    00265 {
    00266 public:
    00267   MittelmannDistCntrlDiri2()
    00268   {}
    00269   virtual ~MittelmannDistCntrlDiri2()
    00270   {}
    00271   virtual bool InitializeProblem(Index N)
    00272   {
    00273     if (N<1) {
    00274       printf("N has to be at least 1.");
    00275       return false;
    00276     }
    00277     Number alpha = 0.;
    00278     Number lb_y = -1e20;
    00279     Number ub_y = 0.185;
    00280     Number lb_u = 1.5;
    00281     Number ub_u = 4.5;
    00282     Number u_init = (ub_u+lb_u)/2.;
    00283
    00284     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00285     return true;
    00286   }
    00287 protected:
    00289   virtual Number y_d_cont(Number x1, Number x2)  const
    00290   {
    00291     return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
    00292   }
    00294   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00295   {
    00296     return pow(y,3) - y - u;
    00297   }
    00299   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00300   {
    00301     return 3.*y*y - 1.;
    00302   }
    00304   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00305   {
    00306     return -1.;
    00307   }
    00309   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00310   {
    00311     return 6.*y;
    00312   }
    00313 private:
    00316   MittelmannDistCntrlDiri2(const MittelmannDistCntrlDiri2&);
    00317   MittelmannDistCntrlDiri2& operator=(const MittelmannDistCntrlDiri2&);
    00319 };
    00320
    00322 class MittelmannDistCntrlDiri3 : public MittelmannDistCntrlDiriBase
    00323 {
    00324 public:
    00325   MittelmannDistCntrlDiri3()
    00326       :
    00327       pi_(4.*atan(1.))
    00328   {}
    00329   virtual ~MittelmannDistCntrlDiri3()
    00330   {}
    00331   virtual bool InitializeProblem(Index N)
    00332   {
    00333     if (N<1) {
    00334       printf("N has to be at least 1.");
    00335       return false;
    00336     }
    00337     Number alpha = 0.001;
    00338     Number lb_y = -1e20;
    00339     Number ub_y = 0.11;
    00340     Number lb_u = -5;
    00341     Number ub_u = 5.;
    00342     Number u_init = (ub_u+lb_u)/2.;
    00343
    00344     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00345     return true;
    00346   }
    00347 protected:
    00349   virtual Number y_d_cont(Number x1, Number x2)  const
    00350   {
    00351     return sin(2.*pi_*x1)*sin(2.*pi_*x2);
    00352   }
    00354   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00355   {
    00356     return -exp(y) - u;
    00357   }
    00359   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00360   {
    00361     return -exp(y);
    00362   }
    00364   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00365   {
    00366     return -1.;
    00367   }
    00369   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00370   {
    00371     return -exp(y);
    00372   }
    00373 private:
    00376   MittelmannDistCntrlDiri3(const MittelmannDistCntrlDiri3&);
    00377   MittelmannDistCntrlDiri3& operator=(const MittelmannDistCntrlDiri3&);
    00379
    00380   const Number pi_;
    00381 };
    00382
    00383 class MittelmannDistCntrlDiri3a : public MittelmannDistCntrlDiriBase
    00384 {
    00385 public:
    00386   MittelmannDistCntrlDiri3a()
    00387       :
    00388       pi_(4.*atan(1.))
    00389   {}
    00390   virtual ~MittelmannDistCntrlDiri3a()
    00391   {}
    00392   virtual bool InitializeProblem(Index N)
    00393   {
    00394     if (N<1) {
    00395       printf("N has to be at least 1.");
    00396       return false;
    00397     }
    00398     Number alpha = 0.;
    00399     Number lb_y = -1e20;
    00400     Number ub_y = 0.11;
    00401     Number lb_u = -5;
    00402     Number ub_u = 5.;
    00403     Number u_init = (ub_u+lb_u)/2.;
    00404
    00405     SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
    00406     return true;
    00407   }
    00408 protected:
    00410   virtual Number y_d_cont(Number x1, Number x2)  const
    00411   {
    00412     return sin(2.*pi_*x1)*sin(2.*pi_*x2);
    00413   }
    00415   virtual Number d_cont(Number x1, Number x2, Number y, Number u)  const
    00416   {
    00417     return -exp(y) - u;
    00418   }
    00420   virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u)  const
    00421   {
    00422     return -exp(y);
    00423   }
    00425   virtual Number d_cont_du(Number x1, Number x2, Number y, Number u)  const
    00426   {
    00427     return -1.;
    00428   }
    00430   virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u)  const
    00431   {
    00432     return -exp(y);
    00433   }
    00434 private:
    00437   MittelmannDistCntrlDiri3a(const MittelmannDistCntrlDiri3a&);
    00438   MittelmannDistCntrlDiri3a& operator=(const MittelmannDistCntrlDiri3a&);
    00440
    00441   const Number pi_;
    00442 };
    00443
    00444 #endif