Title: | 'clarabel' Plug-in for the 'R' Optimization Infrastructure |
---|---|
Description: | Enhances the 'R' Optimization Infrastructure ('ROI') package with the 'clarabel' solver for solving convex cone problems. More information about 'clarabel' can be found at <https://oxfordcontrol.github.io/ClarabelDocs/stable/>. |
Authors: | Benjamin Schwendinger [aut, cre] |
Maintainer: | Benjamin Schwendinger <[email protected]> |
License: | GPL-3 |
Version: | 0.3 |
Built: | 2024-11-12 03:40:21 UTC |
Source: | https://github.com/cran/ROI.plugin.clarabel |
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) obj <- L_objective(c(1, 1)) ## NOTE: chol(diag(2)) == diag(2) con <- C_constraint(L = rbind(0, -diag(2)), cones = K_soc(3), rhs = c(1, 0, 0)) op <- OP(obj, con, maximum = TRUE) x <- ROI_solve(op, solver = "clarabel") x ## Optimal solution found. ## The objective value is: 1.414214e+00 solution(x) ## [1] 0.7071068 0.7071068
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) obj <- L_objective(c(1, 1)) ## NOTE: chol(diag(2)) == diag(2) con <- C_constraint(L = rbind(0, -diag(2)), cones = K_soc(3), rhs = c(1, 0, 0)) op <- OP(obj, con, maximum = TRUE) x <- ROI_solve(op, solver = "clarabel") x ## Optimal solution found. ## The objective value is: 1.414214e+00 solution(x) ## [1] 0.7071068 0.7071068
The following example is also known as Problem 10
from the
Hock-Schittkowski-Collection Hock and Schittkowski (1981)
.
W. Hock, K. Schittkowski (1981): Test Examples for Nonlinear Programming Codes, Lecture Notes in Economics and Mathematical Systems, Vol. 187, Springer
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) obj <- L_objective(c(1, -1)) L <- chol(rbind(c(3, -1), c(-1, 1))) con <- C_constraint(L = rbind(0, -L), cones = K_soc(3), rhs = c(1, 0, 0)) op <- OP(objective = obj, constraints = con, bounds = V_bound(li = 1:2, lb = rep(-Inf, 2))) x <- ROI_solve(op, solver="clarabel") x ## Optimal solution found. ## The objective value is: -1.000000e+00 solution(x) ## [1] -4.622464e-16 1.000000e+00
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) obj <- L_objective(c(1, -1)) L <- chol(rbind(c(3, -1), c(-1, 1))) con <- C_constraint(L = rbind(0, -L), cones = K_soc(3), rhs = c(1, 0, 0)) op <- OP(objective = obj, constraints = con, bounds = V_bound(li = 1:2, lb = rep(-Inf, 2))) x <- ROI_solve(op, solver="clarabel") x ## Optimal solution found. ## The objective value is: -1.000000e+00 solution(x) ## [1] -4.622464e-16 1.000000e+00
The following example is originally from the CVXOPT
(https://cvxopt.org/userguide/coneprog.html) homepage.
subject to
Andersen, Martin S and Dahl, Joachim and Vandenberghe, Lieven (2016) CVXOPT: A Python package for convex optimization, version 1.1.8, https://cvxopt.org/
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) lo <- L_objective(c(-2, 1, 5)) lc1 <- rbind(c(12, 6, -5), c(13, -3, -5), c(12, -12, 6)) lc2 <- rbind(c(3, -6, 10), c(3, -6, -2), c(-1, -9, -2), c(1, 19, -3)) lc <- C_constraint(L = rbind(lc1, lc2), cones = K_soc(c(3, 4)), rhs = c(c(-12, -3, -2), c(27, 0, 3, -42))) vb <- V_bound(li = 1:3, lb = rep(-Inf, 3)) op <- OP(objective = lo, constraints = lc, bounds = vb) x <- ROI_solve(op, solver="clarabel") x ## Optimal solution found. ## The objective value is: -3.834637e+01 solution(x) ## [1] -5.014767 -5.766924 -8.521796
Sys.setenv("ROI_LOAD_PLUGINS" = FALSE) library(ROI) library(ROI.plugin.clarabel) lo <- L_objective(c(-2, 1, 5)) lc1 <- rbind(c(12, 6, -5), c(13, -3, -5), c(12, -12, 6)) lc2 <- rbind(c(3, -6, 10), c(3, -6, -2), c(-1, -9, -2), c(1, 19, -3)) lc <- C_constraint(L = rbind(lc1, lc2), cones = K_soc(c(3, 4)), rhs = c(c(-12, -3, -2), c(27, 0, 3, -42))) vb <- V_bound(li = 1:3, lb = rep(-Inf, 3)) op <- OP(objective = lo, constraints = lc, bounds = vb) x <- ROI_solve(op, solver="clarabel") x ## Optimal solution found. ## The objective value is: -3.834637e+01 solution(x) ## [1] -5.014767 -5.766924 -8.521796
Extension of the utility function vech performing a half-vectorization on the given matrices.
vech(..., lower = TRUE, scale = FALSE)
vech(..., lower = TRUE, scale = FALSE)
... |
one or more matrices to be half-vectorized. |
lower |
use lower or upper half-vectorization |
scale |
whether the lower/upper triangular elements are scaled |
a matrix