# source:trunk/Ipopt/contrib/RInterface/man/ipoptr-package.Rd@1861

Last change on this file since 1861 was 1861, checked in by andreasw, 3 years ago

moved Ipopt trunk from Common Public License to successor Eclispe Public License (see e.g. http://www.ibm.com/developerworks/library/os-cplfaq.html)

File size: 5.2 KB
Line
1\name{ipoptr-package}
2\alias{ipoptr-package}
3\docType{package}
4\title{
5R interface to Ipopt
6}
7\description{
8ipoptr is an R interface to Ipopt (Interior Point Optimizer), an open source software
9package for large-scale nonlinear optimization. It can be used to solve general nonlinear
10programming problems with nonlinear constraints and lower and upper bounds for the controls.
11Ipopt is written in C++ and is released as open source code under the Eclipse Public License (EPL).
12It is available from the COIN-OR initiative. The code has been written by Carl Laird and
13Andreas Waechter, who is the COIN project leader for Ipopt.
14
15Ipopt is designed to find (local) solutions of mathematical optimization problems of the from
16
17   min     f(x)
18x in R^n
19
20s.t.       g_L <= g(x) <= g_U
21           x_L <=  x   <= x_U
22
23where f(x): R^n --> R is the objective function, and g(x): R^n --> R^m are the constraint
24functions. The vectors g_L and g_U denote the lower and upper bounds on the constraints,
25and the vectors x_L and x_U are the bounds on the variables x. The functions f(x) and g(x)
26can be nonlinear and nonconvex, but should be twice continuously differentiable. Note that
27equality constraints can be formulated in the above formulation by setting the corresponding
28components of g_L and g_U to the same value.
29}
30\author{
31Jelmer Ypma
32}
33\references{
34A. Waechter and L. T. Biegler, On the Implementation of a Primal-Dual Interior Point Filter Line Search Algorithm for Large-Scale Nonlinear Programming, Mathematical Programming 106(1), pp. 25-57, 2006
35}
36\keyword{ optimize }
37\keyword{ interface }
38\seealso{
43}
44\note{See ?ipoptr for more examples.}
45\examples{
46# Example problem, number 71 from the Hock-Schittkowsky test suite
47#
48# \min_{x} x1*x4*(x1 + x2 + x3) + x3
49# s.t.
50#    x1*x2*x3*x4 >= 25
51#    x1^2 + x2^2 + x3^2 + x4^2 = 40
52#    1 <= x1,x2,x3,x4 <= 5
53#
54# x0 = (1,5,5,1)
55#
56# optimal solution = (1.00000000, 4.74299963, 3.82114998, 1.37940829)
57#
58# Adapted from the Ipopt C++ interface example.
59
60
61library('ipoptr')
62
63#
64# f(x) = x1*x4*(x1 + x2 + x3) + x3
65#
66eval_f <- function( x ) {
67    return( x[1]*x[4]*(x[1] + x[2] + x[3]) + x[3] )
68}
69
70eval_grad_f <- function( x ) {
71    return( c( x[1] * x[4] + x[4] * (x[1] + x[2] + x[3]),
72               x[1] * x[4],
73               x[1] * x[4] + 1.0,
74               x[1] * (x[1] + x[2] + x[3]) ) )
75}
76
77# constraint functions
78eval_g <- function( x ) {
79    return( c( x[1] * x[2] * x[3] * x[4],
80               x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2 ) )
81}
82
83# The Jacobian for this problem is dense
84eval_jac_g_structure <- list( c(1,2,3,4), c(1,2,3,4) )
85
86eval_jac_g <- function( x ) {
87    return( c ( x[2]*x[3]*x[4],
88                x[1]*x[3]*x[4],
89                x[1]*x[2]*x[4],
90                x[1]*x[2]*x[3],
91                2.0*x[1],
92                2.0*x[2],
93                2.0*x[3],
94                2.0*x[4] ) )
95}
96
97# The Hessian for this problem is actually dense,
98# This is a symmetric matrix, fill the lower left triangle only.
99eval_h_structure <- list( c(1), c(1,2), c(1,2,3), c(1,2,3,4) )
100
101eval_h <- function( x, obj_factor, hessian_lambda ) {
102
103    values <- numeric(10)
104    values[1] = obj_factor * (2*x[4]) # 1,1
105
106    values[2] = obj_factor * (x[4])   # 2,1
107    values[3] = 0                     # 2,2
108
109    values[4] = obj_factor * (x[4])   # 3,1
110    values[5] = 0                     # 4,2
111    values[6] = 0                     # 3,3
112
113    values[7] = obj_factor * (2*x[1] + x[2] + x[3]) # 4,1
114    values[8] = obj_factor * (x[1])                 # 4,2
115    values[9] = obj_factor * (x[1])                 # 4,3
116    values[10] = 0                                  # 4,4
117
118
119    # add the portion for the first constraint
120    values[2] = values[2] + hessian_lambda[1] * (x[3] * x[4]) # 2,1
121
122    values[4] = values[4] + hessian_lambda[1] * (x[2] * x[4]) # 3,1
123    values[5] = values[5] + hessian_lambda[1] * (x[1] * x[4]) # 3,2
124
125    values[7] = values[7] + hessian_lambda[1] * (x[2] * x[3]) # 4,1
126    values[8] = values[8] + hessian_lambda[1] * (x[1] * x[3]) # 4,2
127    values[9] = values[9] + hessian_lambda[1] * (x[1] * x[2]) # 4,3
128
129    # add the portion for the second constraint
130    values[1] = values[1] + hessian_lambda[2] * 2 # 1,1
131    values[3] = values[3] + hessian_lambda[2] * 2 # 2,2
132    values[6] = values[6] + hessian_lambda[2] * 2 # 3,3
133    values[10] = values[10] + hessian_lambda[2] * 2 # 4,4
134
135    return ( values )
136}
137
138# initial values
139x0 <- c( 1, 5, 5, 1 )
140
141# lower and upper bounds of control
142lb <- c( 1, 1, 1, 1 )
143ub <- c( 5, 5, 5, 5 )
144
145# lower and upper bounds of constraints
146constraint_lb <- c(  25, 40 )
147constraint_ub <- c( Inf, 40 )
148
149
150opts <- list("print_level"=0,
151             "file_print_level"=12,
152             "output_file"="hs071_nlp.out")
153
154print( ipoptr( x0=x0,
155               eval_f=eval_f,