solve(prob, alg) minimizes an OptimizationProblem(). The solution
has sol$u (the minimizer, a named vector), sol$objective (the cost
there), sol$retcode and sol$original (the result of the underlying
optimizer), and supports symbolic indexing: sol[x], sol$ps[a].
Usage
# S3 method for class 'OptimizationProblem'
solve(a, b, ...)Arguments
- a
An
OptimizationProblem.- b
An algorithm, see optimization_algorithms; by default
AugLag()for problems with constraints andLBFGSB()otherwise,BranchAndBound()for problems with integer unknowns andWeightedSumScan()for multiobjective problems.- ...
Solver options:
maxiters,abstol,reltol.
Details
Problems with integer or binary unknowns are solved by
BranchAndBound() (the default for them), and multiobjective problems
(built with multiobjective = TRUE) by NSGA2() or WeightedSumScan()
(the default); their solution holds the Pareto set in sol$u and the
Pareto front in sol$objective, see multiobjective_algorithms.
Examples
x <- Variable("x"); y <- Variable("y")
sys <- complete(System(list(), costs = list((1 - x)^2 + 100 * (y - x^2)^2), name = "rosenbrock",
constraints = list(Inequality(x^2 + y^2, 1))))
sol <- solve(OptimizationProblem(sys, list(x ~ 0, y ~ 0)), AugLag())
sol$u; sol$objective; sol$retcode
#> x y
#> 0.7864152 0.6176983
#> [1] 0.04567481
#> [1] "Success"