Title: | 'alabama' Plug-in for the 'R' Optimization Infrastructure |
---|---|
Description: | Enhances the R Optimization Infrastructure ('ROI') package with the 'alabama' solver for solving nonlinear optimization problems. |
Authors: | Florian Schwendinger [aut, cre] |
Maintainer: | Florian Schwendinger <[email protected]> |
License: | GPL-3 |
Version: | 1.0-0 |
Built: | 2024-11-09 02:35:49 UTC |
Source: | https://github.com/r-forge/roi |
The following example is also known as Rosenbrock's banana function (https://en.wikipedia.org/wiki/Rosenbrock_function).
Solution: c(1, 1)
library(ROI) f <- function(x) { return( 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 ) } f.gradient <- function(x) { return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]), 200 * (x[2] - x[1] * x[1])) ) } x <- OP(objective = F_objective(f, n = 2L, G = f.gradient), bounds = V_bound(li = 1:2, ui = 1:2, lb = c(-3, -3), ub = c(3, 3))) nlp <- ROI_solve(x, solver = "alabama", start = c(-2, 2.4), method = "BFGS") nlp ## Optimal solution found. ## The objective value is: 3.049556e-23 solution(nlp) ## [1] 1 1
library(ROI) f <- function(x) { return( 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 ) } f.gradient <- function(x) { return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]), 200 * (x[2] - x[1] * x[1])) ) } x <- OP(objective = F_objective(f, n = 2L, G = f.gradient), bounds = V_bound(li = 1:2, ui = 1:2, lb = c(-3, -3), ub = c(3, 3))) nlp <- ROI_solve(x, solver = "alabama", start = c(-2, 2.4), method = "BFGS") nlp ## Optimal solution found. ## The objective value is: 3.049556e-23 solution(nlp) ## [1] 1 1
The following example solves problem 16 from the Hock-Schittkowski-Collection
.
Solution: c(0.5, 0.25)
library(ROI) f <- function(x) { return( 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 ) } f.gradient <- function(x) { return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]), 200 * (x[2] - x[1] * x[1])) ) } x <- OP( objective = F_objective(f, n=2L, G=f.gradient), constraints = c(F_constraint(F=function(x) x[1] + x[2]^2, ">=", 0, J=function(x) c(1, 2*x[2])), F_constraint(F=function(x) x[1]^2 + x[2], ">=", 0, J=function(x) c(2*x[1], x[2]))), bounds = V_bound(li=1:2, ui=1:2, lb=c(-2, -Inf), ub=c(0.5, 1)) ) nlp <- ROI_solve(x, solver="alabama", start=c(-2, 1)) nlp ## Optimal solution found. ## The objective value is: 2.499999e-01 solution(nlp) ## [1] 0.5000001 0.2499994
library(ROI) f <- function(x) { return( 100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 ) } f.gradient <- function(x) { return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]), 200 * (x[2] - x[1] * x[1])) ) } x <- OP( objective = F_objective(f, n=2L, G=f.gradient), constraints = c(F_constraint(F=function(x) x[1] + x[2]^2, ">=", 0, J=function(x) c(1, 2*x[2])), F_constraint(F=function(x) x[1]^2 + x[2], ">=", 0, J=function(x) c(2*x[1], x[2]))), bounds = V_bound(li=1:2, ui=1:2, lb=c(-2, -Inf), ub=c(0.5, 1)) ) nlp <- ROI_solve(x, solver="alabama", start=c(-2, 1)) nlp ## Optimal solution found. ## The objective value is: 2.499999e-01 solution(nlp) ## [1] 0.5000001 0.2499994
The following example solves exmaple 36 from the Hock-Schittkowski-Collection
.
library(ROI) hs036_obj <- function(x) { -x[1] * x[2] * x[3] } hs036_con <- function(x) { x[1] + 2 * x[2] + 2 * x[3] } x <- OP( objective = F_objective(hs036_obj, n = 3L), constraints = F_constraint(hs036_con, "<=", 72), bounds = V_bound(ub = c(20, 11, 42)) ) nlp <- ROI_solve(x, solver = "alabama", start = c(10, 10, 10)) nlp ## Optimal solution found. ## The objective value is: -3.300000e+03 solution(nlp, "objval") ## [1] -3300 solution(nlp) ## [1] 20 11 15
library(ROI) hs036_obj <- function(x) { -x[1] * x[2] * x[3] } hs036_con <- function(x) { x[1] + 2 * x[2] + 2 * x[3] } x <- OP( objective = F_objective(hs036_obj, n = 3L), constraints = F_constraint(hs036_con, "<=", 72), bounds = V_bound(ub = c(20, 11, 42)) ) nlp <- ROI_solve(x, solver = "alabama", start = c(10, 10, 10)) nlp ## Optimal solution found. ## The objective value is: -3.300000e+03 solution(nlp, "objval") ## [1] -3300 solution(nlp) ## [1] 20 11 15