Skip to contents

ConeConstraint(g, set) is one convex cone constraint of a ConvexOptimizationProblem(): g(u, p) returns the affine map whose image must lie in the MathOptInterface vector cone set (MOI$Zeros, $Nonnegatives, $Nonpositives, $SecondOrderCone, ...). The output length of g must equal MOI$dimension(set). Each ConeConstraint maps to one entry of the solution's dual, in the order the constraints are given, already in the user's variables: >= is $Nonnegatives, <= $Nonpositives and == $Zeros. set is read once when the cache is built; a set carrying data derived from the parameters (MOI$PowerCone(p[1])) is not updated by reinit(); rebuild with solve(remake(prob, p = ...), alg) instead.

Usage

ConeConstraint(g, set)

ConvexMOI(optimizer_constructor = ClarabelOptimizer)

Arguments

g

The map g(u, p).

set

A vector set of MOI.

optimizer_constructor

ClarabelOptimizer or a call of it.

Value

A ConeConstraint or a ConvexMOI algorithm.

Details

ConvexMOI(optimizer_constructor) certifies convexity (SymbolicAnalysis rules, see analyze()), lowers the objective and each ConeConstraint to a cone and solves with the optimizer (ClarabelOptimizer()). The objective may be affine or contain atoms lowered through their epigraph: norm(A %*% u - b, "2") introduces an epigraph variable tau with (tau, A u - b) in a second order cone and minimizes tau. The atoms are norm(w, type) of a vector expression w in u with the types of base::norm() ("O" or "1" the one norm, "I" or "M" the infinity norm, "F", "E" or "2" the two norm, or the order 1, 2, Inf), lowered to NormOneCone, SecondOrderCone or NormInfinityCone, and exp(w) and log(w) of scalar affine w (ExponentialCone); log is concave, so it is bounded below and must enter the objective negatively.

The functions are traced once, on symbolic vectors u and p that support arithmetic, indexing, sum, exp, log, %*% with numeric matrices and norm (the last two inside the traced functions only). Parameters are first class: reinit() re-solves the cache returned by init() at a new p without symbolic work, evaluating the cone data as the affine function of p extracted at init. The solution has u, objective, dual (one vector per ConeConstraint, NaN when the solve gives no dual solution), retcode, original (the solved model, with its MathOptInterface statuses and the Clarabel solver) and cache.

Examples

cons <- list(ConeConstraint(function(u, p) u[1] + u[2] - 1, MOI$Zeros(1)),
             ConeConstraint(function(u, p) c(u[1], u[2]), MOI$Nonnegatives(2)))
prob <- ConvexOptimizationProblem(function(u, p) u[1] + 2 * u[2], c(0.5, 0.5), constraints = cons)
sol <- solve(prob, ConvexMOI())
sol$u; sol$objective; sol$dual
#> [1] 1.000000e+00 1.811154e-09
#> [1] 1
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 6.053942e-10 1.000000e+00
#> 
A <- matrix(c(1, 1), 2, 1)
sol <- solve(ConvexOptimizationProblem(function(u, p) norm(A %*% u - c(0, 2), "2"), 0),
  ConvexMOI())
sol$u
#> [1] 1