View source: R/252_transforms_partial_optimize.R
| partial_optimize | R Documentation |
Builds an Expression representing the optimal value of prob as
a function of the variables you choose NOT to optimise over. Useful
for two-stage / hierarchical optimisation, custom atom definitions,
and embedding sub-problems inside larger problems.
partial_optimize(
prob,
opt_vars = NULL,
dont_opt_vars = NULL,
solver = NULL,
...
)
prob |
A Problem to partially optimise. |
opt_vars |
Optional list of Variables to optimise over. |
dont_opt_vars |
Optional list of Variables to keep as free arguments of the resulting expression. |
solver |
Optional solver name (passed to |
... |
Additional named arguments forwarded to |
Exactly one of opt_vars or dont_opt_vars may be NULL; the
missing list is taken to be the complement (relative to the full
list of variables in prob). If both are supplied, they must
together cover every variable in prob.
The returned PartialProblem is an Expression with scalar shape:
it is convex when prob is DCP with a Minimize objective and
concave when DCP with Maximize. Embed it like any other
expression in a larger Problem; the larger problem's canonicalizer
will pull the inner objective and constraints into the outer cone
form so a single solve handles both layers.
A PartialProblem expression.
Problem, psolve()
## Not run:
x <- Variable(3)
t <- Variable(3)
abs_x <- partial_optimize(
Problem(Minimize(sum_entries(t)), list(-t <= x, x <= t)),
opt_vars = list(t)
)
## abs_x is now an expression of x alone, equivalent to sum(abs(x)).
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.