Ipopt  3.12.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MittelmannDistCntrlDiri.hpp
Go to the documentation of this file.
1 // Copyright (C) 2005, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: MittelmannDistCntrlDiri.hpp 2005 2011-06-06 12:55:16Z stefan $
6 //
7 // Authors: Andreas Waechter IBM 2005-10-18
8 // based on MyNLP.hpp
9 
10 #ifndef __MITTELMANNDISTRCNTRLDIRI_HPP__
11 #define __MITTELMANNDISTRCNTRLDIRI_HPP__
12 
13 #include "IpTNLP.hpp"
14 #include "RegisteredTNLP.hpp"
15 
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #else
19 #include "configall_system.h"
20 #endif
21 
22 #ifdef HAVE_CMATH
23 # include <cmath>
24 #else
25 # ifdef HAVE_MATH_H
26 # include <math.h>
27 # else
28 # error "don't have header file for math"
29 # endif
30 #endif
31 
32 #ifdef HAVE_CSTDIO
33 # include <cstdio>
34 #else
35 # ifdef HAVE_STDIO_H
36 # include <stdio.h>
37 # else
38 # error "don't have header file for stdio"
39 # endif
40 #endif
41 
42 using namespace Ipopt;
43 
51 {
52 public:
56 
58  virtual ~MittelmannDistCntrlDiriBase();
59 
63  virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
64  Index& nnz_h_lag, IndexStyleEnum& index_style);
65 
67  virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
68  Index m, Number* g_l, Number* g_u);
69 
71  virtual bool get_starting_point(Index n, bool init_x, Number* x,
72  bool init_z, Number* z_L, Number* z_U,
73  Index m, bool init_lambda,
74  Number* lambda);
75 
77  virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
78 
80  virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
81 
83  virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
84 
89  virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
90  Index m, Index nele_jac, Index* iRow, Index *jCol,
91  Number* values);
92 
97  virtual bool eval_h(Index n, const Number* x, bool new_x,
98  Number obj_factor, Index m, const Number* lambda,
99  bool new_lambda, Index nele_hess, Index* iRow,
100  Index* jCol, Number* values);
101 
103 
105  virtual bool get_scaling_parameters(Number& obj_scaling,
106  bool& use_x_scaling, Index n,
107  Number* x_scaling,
108  bool& use_g_scaling, Index m,
109  Number* g_scaling);
110 
115  virtual void finalize_solution(SolverReturn status,
116  Index n, const Number* x, const Number* z_L, const Number* z_U,
117  Index m, const Number* g, const Number* lambda,
118  Number obj_value,
119  const IpoptData* ip_data,
122 
123 protected:
127  void SetBaseParameters(Index N, Number alpha, Number lb_y,
128  Number ub_y, Number lb_u, Number ub_u,
129  Number u_init);
130 
134  virtual Number y_d_cont(Number x1, Number x2) const =0;
136  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const =0;
138  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const =0;
140  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const =0;
142  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const =0;
144 
145 private:
160 
185 
190  inline Index y_index(Index i, Index j) const
191  {
192  return j + (N_+2)*i;
193  }
196  inline Index u_index(Index i, Index j) const
197  {
198  return (N_+2)*(N_+2) + (j-1) + (N_)*(i-1);
199  }
202  inline Index pde_index(Index i, Index j) const
203  {
204  return (j-1) + N_*(i-1);
205  }
207  inline Number x1_grid(Index i) const
208  {
209  return h_*(Number)i;
210  }
212  inline Number x2_grid(Index i) const
213  {
214  return h_*(Number)i;
215  }
217 };
218 
221 {
222 public:
224  {}
225 
227  {}
228 
229  virtual bool InitializeProblem(Index N)
230  {
231  if (N<1) {
232  printf("N has to be at least 1.");
233  return false;
234  }
235  Number alpha = 0.001;
236  Number lb_y = -1e20;
237  Number ub_y = 0.185;
238  Number lb_u = 1.5;
239  Number ub_u = 4.5;
240  Number u_init = (ub_u+lb_u)/2.;
241 
242  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
243  return true;
244  }
245 protected:
247  virtual Number y_d_cont(Number x1, Number x2) const
248  {
249  return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
250  }
252  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
253  {
254  return pow(y,3) - y - u;
255  }
257  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
258  {
259  return 3.*y*y - 1.;
260  }
262  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
263  {
264  return -1.;
265  }
267  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
268  {
269  return 6.*y;
270  }
271 private:
277 };
278 
281 {
282 public:
284  {}
286  {}
287  virtual bool InitializeProblem(Index N)
288  {
289  if (N<1) {
290  printf("N has to be at least 1.");
291  return false;
292  }
293  Number alpha = 0.;
294  Number lb_y = -1e20;
295  Number ub_y = 0.185;
296  Number lb_u = 1.5;
297  Number ub_u = 4.5;
298  Number u_init = (ub_u+lb_u)/2.;
299 
300  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
301  return true;
302  }
303 protected:
305  virtual Number y_d_cont(Number x1, Number x2) const
306  {
307  return 1. + 2.*(x1*(x1-1.)+x2*(x2-1.));
308  }
310  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
311  {
312  return pow(y,3) - y - u;
313  }
315  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
316  {
317  return 3.*y*y - 1.;
318  }
320  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
321  {
322  return -1.;
323  }
325  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
326  {
327  return 6.*y;
328  }
329 private:
335 };
336 
339 {
340 public:
342  :
343  pi_(4.*atan(1.))
344  {}
346  {}
347  virtual bool InitializeProblem(Index N)
348  {
349  if (N<1) {
350  printf("N has to be at least 1.");
351  return false;
352  }
353  Number alpha = 0.001;
354  Number lb_y = -1e20;
355  Number ub_y = 0.11;
356  Number lb_u = -5;
357  Number ub_u = 5.;
358  Number u_init = (ub_u+lb_u)/2.;
359 
360  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
361  return true;
362  }
363 protected:
365  virtual Number y_d_cont(Number x1, Number x2) const
366  {
367  return sin(2.*pi_*x1)*sin(2.*pi_*x2);
368  }
370  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
371  {
372  return -exp(y) - u;
373  }
375  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
376  {
377  return -exp(y);
378  }
380  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
381  {
382  return -1.;
383  }
385  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
386  {
387  return -exp(y);
388  }
389 private:
395 
396  const Number pi_;
397 };
398 
400 {
401 public:
403  :
404  pi_(4.*atan(1.))
405  {}
407  {}
408  virtual bool InitializeProblem(Index N)
409  {
410  if (N<1) {
411  printf("N has to be at least 1.");
412  return false;
413  }
414  Number alpha = 0.;
415  Number lb_y = -1e20;
416  Number ub_y = 0.11;
417  Number lb_u = -5;
418  Number ub_u = 5.;
419  Number u_init = (ub_u+lb_u)/2.;
420 
421  SetBaseParameters(N, alpha, lb_y, ub_y, lb_u, ub_u, u_init);
422  return true;
423  }
424 protected:
426  virtual Number y_d_cont(Number x1, Number x2) const
427  {
428  return sin(2.*pi_*x1)*sin(2.*pi_*x2);
429  }
431  virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
432  {
433  return -exp(y) - u;
434  }
436  virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
437  {
438  return -exp(y);
439  }
441  virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
442  {
443  return -1.;
444  }
446  virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
447  {
448  return -exp(y);
449  }
450 private:
456 
457  const Number pi_;
458 };
459 
460 #endif
const Number pi_
Value of pi (made available for convenience)
Number * x
Input: Starting point Output: Optimal solution.
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Class for all IPOPT specific calculated quantities.
Number Number Index Number Number Index Index Index index_style
indexing style for iRow &amp; jCol, 0 for C style, 1 for Fortran style
Number u_init_
Initial value for the constrols u.
Base class for distributed control problems with Dirichlet boundary conditions, as formulated by Hans...
Number Number Index m
Number of constraints.
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB Eval_Jac_G_CB Eval_H_CB eval_h
Callback function for evaluating Hessian of Lagrangian function.
Class implementating Example 2.
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Class implementating Example 3.
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB eval_grad_f
Callback function for evaluating gradient of objective function.
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Number x1_grid(Index i) const
Compute the grid coordinate for given index in x1 direction.
virtual Number d_cont_dy(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
Index u_index(Index i, Index j) const
Translation of mesh point indices to NLP variable indices for u(x_ij)
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB Eval_Grad_F_CB Eval_Jac_G_CB eval_jac_g
Callback function for evaluating Jacobian of constraint functions.
Class implementating Example 1.
SolverReturn
enum for the return from the optimize algorithm (obviously we need to add more)
Definition: IpAlgTypes.hpp:22
Number lb_u_
overall lower bound on u
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Index y_index(Index i, Index j) const
Translation of mesh point indices to NLP variable indices for y(x_ij)
Number x2_grid(Index i) const
Compute the grid coordinate for given index in x2 direction.
Number alpha_
Weighting parameter for the control target deviation functional in the objective. ...
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
Number Number Index Number Number Index Index Index Eval_F_CB Eval_G_CB eval_g
Callback function for evaluating constraint functions.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
Number Number * x_scaling
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Class implemented the NLP discretization of.
virtual Number d_cont_dydy(Number x1, Number x2, Number y, Number u) const
Second partial derivative of forcing function w.r.t y,y.
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
virtual Number d_cont(Number x1, Number x2, Number y, Number u) const
Forcing function for the elliptic equation.
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Number Number Number * g_scaling
virtual Number y_d_cont(Number x1, Number x2) const
Target profile function for y.
Number ub_u_
overall upper bound on u
virtual Number d_cont_du(Number x1, Number x2, Number y, Number u) const
First partial derivative of forcing function w.r.t.
IndexStyleEnum
overload this method to return the number of variables and constraints, and the number of non-zeros i...
Definition: IpTNLP.hpp:80
Number * y_d_
Array for the target profile for y.
Number ub_y_
overall upper bound on y
virtual bool InitializeProblem(Index N)
Initialize internal parameters, where N is a parameter determining the problme size.
Number obj_scaling
Index N_
Number of mesh points in one dimension (excluding boundary)
Number Number Index Number Number Index Index Index Eval_F_CB eval_f
Callback function for evaluating objective function.
Number lb_y_
overall lower bound on y
const Number pi_
Value of pi (made available for convenience)
Index pde_index(Index i, Index j) const
Translation of interior mesh point indices to the corresponding PDE constraint number.