Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpoptRNLP.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2010 Jelmer Ypma. All Rights Reserved.
3 * This code is published under the Eclipse Public License.
4 *
5 * file: IpoptRNLP.hpp
6 * author: Jelmer Ypma
7 * date: 18 April 2010
8 *
9 * This file defines a C++ class that derives from Ipopt::TNLP. The class
10 * takes care of interaction between Ipopt and user-defined functions in R.
11 *
12 * Financial support of the UK Economic and Social Research Council
13 * through a grant (RES-589-28-0001) to the ESRC Centre for Microdata
14 * Methods and Practice (CeMMAP) is gratefully acknowledged.
15 */
16
17 #ifndef __IpoptRNLP_HPP__
18 #define __IpoptRNLP_HPP__
19
20 #include "IpTNLP.hpp" // ISA TNLP
21
22 #include <assert.h>
23
24 #include <R.h>
25 #include <Rdefines.h>
26 #include <R_ext/Utils.h>
27 // Rdefines.h is somewhat more higher level then Rinternal.h, and is preferred if the code might be shared with S at any stage.
28 // Utils.h defines void R_CheckUserInterrupt(void); to allow user interuption from R
29
30
31 class IpoptRNLP : public Ipopt::TNLP
32 {
33 SEXP R_environment; // this is the environment that the function gets called in. This environment can be used
34 // to pass common data to the R functions.
35 SEXP R_eval_f; // objective function
36 SEXP R_eval_grad_f; // gradient of objective function
37
38 SEXP R_init_values; // vector with initial values, we get the Ipopt::Number of controls from the length of this vector
39
40 SEXP R_lower_bounds; // lower bounds of the control x
41 SEXP R_upper_bounds; // upper bounds of the control x
42
43 SEXP R_eval_g; // function to evaluate constraints
44 SEXP R_eval_jac_g; // function to evaluate jacobian of constraints
45 SEXP R_eval_jac_g_structure; // list with non-zero elements in the Jacobian, this defines the sparse structure
46
47 SEXP R_constraint_lower_bounds; // lower bounds of the contraint function g()
48 SEXP R_constraint_upper_bounds; // upper bounds of the contraint function g()
49
50 SEXP R_eval_h; // function to evaluate Hessian
51 SEXP R_eval_h_structure; // list with non-zero elements of the Hessian, this defines the sparse structure
52
53 SEXP R_result_list; // structure that will contain the return values
54
55 bool d_hessian_approximation; // should we approximate the Hessian? default: false
56
57 int d_num_protected_members; // counter of the number of PROTECT calls of the SEXPs above
58 public:
60 IpoptRNLP();
61
63 virtual ~IpoptRNLP();
64
65 void set_R_environment( SEXP env );
66
67
68 void set_R_eval_f( SEXP f );
69 void set_R_eval_grad_f( SEXP f );
70
71 void set_R_init_values( SEXP x0 );
72 void set_R_lower_bounds( SEXP lb );
73 void set_R_upper_bounds( SEXP ub );
74
75 void set_R_eval_g( SEXP g );
76 void set_R_eval_jac_g( SEXP g );
77 void set_R_eval_jac_g_structure( SEXP s );
78
79 void set_R_constraint_lower_bounds( SEXP lb );
80 void set_R_constraint_upper_bounds( SEXP ub );
81
82 void set_R_eval_h( SEXP h );
83 void set_R_eval_h_structure( SEXP s );
84
85 void set_hessian_approximation( bool b );
86
87 SEXP get_R_result_list();
88
92 virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
93 Ipopt::Index& nnz_h_lag, IndexStyleEnum& Index_style);
94
96 virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
97 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
98
100 virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
101 bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
102 Ipopt::Index m, bool init_lambda,
103 Ipopt::Number* lambda);
104
106 virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number& obj_value);
107
109 virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number* grad_f);
110
112 virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Index m, Ipopt::Number* g);
113
118 virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
119 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, Ipopt::Index *jCol,
120 Ipopt::Number* values);
121
126 virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
127 Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
128 bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow,
129 Ipopt::Index* jCol, Ipopt::Number* values);
130
132
136 virtual void finalize_solution(Ipopt::SolverReturn status,
137 Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U,
138 Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda,
139 Ipopt::Number obj_value,
140 const Ipopt::IpoptData* ip_data,
141 Ipopt::IpoptCalculatedQuantities* ip_cq);
143
144 private:
156 // IpoptRNLP();
157 IpoptRNLP(const IpoptRNLP&);
158 IpoptRNLP& operator=(const IpoptRNLP&);
160 };
161
162
163 #endif
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
IpoptRNLP::set_R_lower_bounds
void set_R_lower_bounds(SEXP lb)
Ipopt::IpoptCalculatedQuantities
Class for all IPOPT specific calculated quantities.
Definition: IpIpoptCalculatedQuantities.hpp:81
IpoptRNLP::R_eval_g
SEXP R_eval_g
Definition: IpoptRNLP.hpp:43
IpoptRNLP::R_eval_h
SEXP R_eval_h
Definition: IpoptRNLP.hpp:50
IpoptRNLP::get_bounds_info
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Method to return the bounds for my problem.
m
Number Number Index m
Number of constraints.
Definition: IpStdCInterface.h:137
IpoptRNLP::set_R_eval_jac_g
void set_R_eval_jac_g(SEXP g)
IpoptRNLP::R_lower_bounds
SEXP R_lower_bounds
Definition: IpoptRNLP.hpp:40
IpoptRNLP::R_upper_bounds
SEXP R_upper_bounds
Definition: IpoptRNLP.hpp:41
IpoptRNLP::R_init_values
SEXP R_init_values
Definition: IpoptRNLP.hpp:38
g
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
Definition: IpStdCInterface.h:238
IpoptRNLP::R_environment
SEXP R_environment
Definition: IpoptRNLP.hpp:33
IpoptRNLP::d_num_protected_members
int d_num_protected_members
Definition: IpoptRNLP.hpp:57
IpoptRNLP::R_eval_h_structure
SEXP R_eval_h_structure
Definition: IpoptRNLP.hpp:51
Ipopt::Number
double Number
Type of all numbers.
Definition: IpTypes.hpp:17
IpoptRNLP::set_R_eval_f
void set_R_eval_f(SEXP f)
IpoptRNLP::d_hessian_approximation
bool d_hessian_approximation
Definition: IpoptRNLP.hpp:55
IpoptRNLP::set_R_eval_jac_g_structure
void set_R_eval_jac_g_structure(SEXP s)
IpoptRNLP::set_R_upper_bounds
void set_R_upper_bounds(SEXP ub)
IpoptRNLP::R_eval_grad_f
SEXP R_eval_grad_f
Definition: IpoptRNLP.hpp:36
IpoptRNLP::get_starting_point
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Method to return the starting point for the algorithm.
IpoptRNLP::get_nlp_info
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &Index_style)
Method to return some info about the nlp.
IpoptRNLP::eval_jac_g
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the jacobian (if &quot;values&quot; is NULL) 2) The values of the jacobia...
IpoptRNLP::set_R_eval_grad_f
void set_R_eval_grad_f(SEXP f)
IpoptRNLP::R_constraint_lower_bounds
SEXP R_constraint_lower_bounds
Definition: IpoptRNLP.hpp:47
IpoptRNLP::operator=
IpoptRNLP & operator=(const IpoptRNLP &)
Ipopt::SolverReturn
SolverReturn
enum for the return from the optimize algorithm (obviously we need to add more)
Definition: IpAlgTypes.hpp:22
nele_jac
Number Number Index Number Number Index nele_jac
Number of non-zero elements in constraint Jacobian.
Definition: IpStdCInterface.h:137
IpoptRNLP::eval_f
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Method to return the objective value.
IpoptRNLP::set_R_environment
void set_R_environment(SEXP env)
Ipopt::IpoptData
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
IpoptRNLP::eval_g
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Method to return the constraint residuals.
IpoptRNLP::set_R_eval_h
void set_R_eval_h(SEXP h)
IpoptRNLP::set_hessian_approximation
void set_hessian_approximation(bool b)
IpoptRNLP::set_R_eval_h_structure
void set_R_eval_h_structure(SEXP s)
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
IpoptRNLP::IpoptRNLP
IpoptRNLP()
default constructor
IpTNLP.hpp
nele_hess
Number Number Index Number Number Index Index nele_hess
Number of non-zero elements in Hessian of Lagrangian.
Definition: IpStdCInterface.h:137
IpoptRNLP
Definition: IpoptRNLP.hpp:31
IpoptRNLP::R_constraint_upper_bounds
SEXP R_constraint_upper_bounds
Definition: IpoptRNLP.hpp:48
IpoptRNLP::set_R_constraint_lower_bounds
void set_R_constraint_lower_bounds(SEXP lb)
IpoptRNLP::set_R_eval_g
void set_R_eval_g(SEXP g)
IpoptRNLP::set_R_constraint_upper_bounds
void set_R_constraint_upper_bounds(SEXP ub)
IpoptRNLP::eval_grad_f
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Method to return the gradient of the objective.
Ipopt::TNLP::IndexStyleEnum
IndexStyleEnum
overload this method to return the number of variables and constraints, and the number of non-zeros i...
Definition: IpTNLP.hpp:80
IpoptRNLP::finalize_solution
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm is complete so the TNLP can store/write the solution...
Ipopt::TNLP
Base class for all NLP&#39;s that use standard triplet matrix form and dense vectors. ...
Definition: IpTNLP.hpp:50
IpoptRNLP::R_eval_jac_g
SEXP R_eval_jac_g
Definition: IpoptRNLP.hpp:44
IpoptRNLP::~IpoptRNLP
virtual ~IpoptRNLP()
default destructor
IpoptRNLP::R_eval_jac_g_structure
SEXP R_eval_jac_g_structure
Definition: IpoptRNLP.hpp:45
IpoptRNLP::R_eval_f
SEXP R_eval_f
Definition: IpoptRNLP.hpp:35
IpoptRNLP::R_result_list
SEXP R_result_list
Definition: IpoptRNLP.hpp:53
IpoptRNLP::eval_h
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Method to return: 1) The structure of the hessian of the lagrangian (if &quot;values&quot; is NULL) 2) The valu...
IpoptRNLP::get_R_result_list
SEXP get_R_result_list()
IpoptRNLP::set_R_init_values
void set_R_init_values(SEXP x0)