Main Page
Namespaces
Classes
Files
File List
File Members
var
build
temp
tmp.niCloInx4p
4.0-0-0
coinor-ipopt
coinor-ipopt-3.10.2
Ipopt
contrib
RInterface
src
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
Generated on Mon Mar 17 2014 19:49:12 by
1.8.1.2