### ** Examples
## Solve the Hock-Schittkowski problem no. 100
x0.hs100 <- c(1, 2, 0, 4, 0, 1, 1)
fn.hs100 <- function(x) {
(x[1]-10)^2 + 5*(x[2]-12)^2 + x[3]^4 + 3*(x[4]-11)^2 + 10*x[5]^6 +
7*x[6]^2 + x[7]^4 - 4*x[6]*x[7] - 10*x[6] - 8*x[7]
}
hin.hs100 <- function(x) {
h <- numeric(4)
h[1] <- 127 - 2*x[1]^2 - 3*x[2]^4 - x[3] - 4*x[4]^2 - 5*x[5]
h[2] <- 282 - 7*x[1] - 3*x[2] - 10*x[3]^2 - x[4] + x[5]
h[3] <- 196 - 23*x[1] - x[2]^2 - 6*x[6]^2 + 8*x[7]
h[4] <- -4*x[1]^2 - x[2]^2 + 3*x[1]*x[2] -2*x[3]^2 - 5*x[6] +11*x[7]
return(h)
}
S <- slsqp(x0.hs100, fn = fn.hs100, # no gradients and jacobians provided
hin = hin.hs100,
control = list(xtol_rel = 1e-8, check_derivatives = TRUE))
For consistency with the rest of the package the inequality sign may be switched from >= to <= in a future nloptr version.
Checking gradients of objective function.
Derivative checker results: 0 error(s) detected.
eval_grad_f[ 1 ] = -1.800000e+01 ~ -1.8e+01 [ 3.023892e-10]
eval_grad_f[ 2 ] = -1.000000e+02 ~ -1.0e+02 [ 8.540724e-14]
eval_grad_f[ 3 ] = 0.000000e+00 ~ 0.0e+00 [ 0.000000e+00]
eval_grad_f[ 4 ] = -4.200000e+01 ~ -4.2e+01 [ 4.384556e-12]
eval_grad_f[ 5 ] = 0.000000e+00 ~ 0.0e+00 [ 0.000000e+00]
eval_grad_f[ 6 ] = -1.877429e-08 ~ 0.0e+00 [-1.877429e-08]
eval_grad_f[ 7 ] = -8.000000e+00 ~ -8.0e+00 [ 6.102499e-10]
Checking gradients of inequality constraints.
Derivative checker results: 0 error(s) detected.
eval_jac_g_ineq[ 1, 1 ] = 4.0e+00 ~ 4.0e+00 [2.355338e-11]
eval_jac_g_ineq[ 2, 1 ] = 7.0e+00 ~ 7.0e+00 [2.278881e-10]
eval_jac_g_ineq[ 3, 1 ] = 2.3e+01 ~ 2.3e+01 [5.297235e-11]
eval_jac_g_ineq[ 4, 1 ] = 2.0e+00 ~ 2.0e+00 [1.311518e-11]
eval_jac_g_ineq[ 1, 2 ] = 9.6e+01 ~ 9.6e+01 [1.985688e-08]
eval_jac_g_ineq[ 2, 2 ] = 3.0e+00 ~ 3.0e+00 [2.191188e-10]
eval_jac_g_ineq[ 3, 2 ] = 4.0e+00 ~ 4.0e+00 [2.355338e-11]
eval_jac_g_ineq[ 4, 2 ] = 1.0e+00 ~ 1.0e+00 [4.978373e-11]
eval_jac_g_ineq[ 1, 3 ] = 1.0e+00 ~ 1.0e+00 [5.631432e-10]
eval_jac_g_ineq[ 2, 3 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 3, 3 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 4, 3 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 1, 4 ] = 3.2e+01 ~ 3.2e+01 [7.445362e-09]
eval_jac_g_ineq[ 2, 4 ] = 1.0e+00 ~ 1.0e+00 [2.909929e-09]
eval_jac_g_ineq[ 3, 4 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 4, 4 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 1, 5 ] = 5.0e+00 ~ 5.0e+00 [2.355325e-11]
eval_jac_g_ineq[ 2, 5 ] = -1.0e+00 ~ -1.0e+00 [2.909929e-09]
eval_jac_g_ineq[ 3, 5 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 4, 5 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 1, 6 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 2, 6 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 3, 6 ] = 1.2e+01 ~ 1.2e+01 [1.720122e-10]
eval_jac_g_ineq[ 4, 6 ] = 5.0e+00 ~ 5.0e+00 [5.781509e-12]
eval_jac_g_ineq[ 1, 7 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 2, 7 ] = 0.0e+00 ~ 0.0e+00 [0.000000e+00]
eval_jac_g_ineq[ 3, 7 ] = -8.0e+00 ~ -8.0e+00 [2.355338e-11]
eval_jac_g_ineq[ 4, 7 ] = -1.1e+01 ~ -1.1e+01 [3.114761e-12]
$par
[1] 2.3304999 1.9513724 -0.4775407 4.3657259 -0.6244871 1.0381315 1.5942274
$value
[1] 680.6301
$iter
[1] 41
$convergence
[1] 4
$message
[1] "NLOPT_XTOL_REACHED: Optimization stopped because xtol_rel or xtol_abs (above) was reached."
## Optimal value of objective function: 690.622270249131 *** WRONG ***
# Even the numerical derivatives seem to be too tight.
# Let's try with a less accurate jacobian.
hinjac.hs100 <- function(x) nl.jacobian(x, hin.hs100, heps = 1e-2)
S <- slsqp(x0.hs100, fn = fn.hs100,
hin = hin.hs100, hinjac = hinjac.hs100,
control = list(xtol_rel = 1e-8))
For consistency with the rest of the package the inequality sign may be switched from >= to <= in a future nloptr version.
$par
[1] 2.2292014 1.7751070 -0.1267445 4.7153404 -0.6301804 0.8819700 1.9371858
$value
[1] 690.6213
$iter
[1] 49
$convergence
[1] 4
$message
[1] "NLOPT_XTOL_REACHED: Optimization stopped because xtol_rel or xtol_abs (above) was reached."
## Optimal value of objective function: 680.630057392593 *** CORRECT ***