latte-optim | R Documentation |
latte_max
and latte_min
use LattE's latte-maximize
and
latte-minimize
functions to find the maximum or minimum of a linear
objective function over the integers points in a polytope (i.e. satisfying
linearity constraints). This makes use of the digging algorithm; see the
LattE manual at http://www.math.ucdavis.edu/~latte for details.
latte_optim(
objective,
constraints,
type = c("max", "min"),
method = c("lp", "cones"),
dir = tempdir(),
opts = "",
quiet = TRUE,
shell = FALSE
)
latte_max(
objective,
constraints,
method = c("lp", "cones"),
dir = tempdir(),
opts = "",
quiet = TRUE
)
latte_min(
objective,
constraints,
method = c("lp", "cones"),
dir = tempdir(),
opts = "",
quiet = TRUE
)
objective |
A linear polynomial to pass to |
constraints |
A collection of linear polynomial (in)equalities that define the feasibility region, the integers in the polytope |
type |
|
method |
Method |
dir |
Directory to place the files in, without an ending / |
opts |
Options; see the LattE manual at http://www.math.ucdavis.edu/~latte |
quiet |
Show latte output |
shell |
Messages the shell code used to do the computation |
A named list with components par
, a named-vector of optimizing
arguments, and value
, the value of the objective function at the
optimial point.
if (has_latte()) {
latte_max(
"-2 x + 3 y",
c("x + y <= 10", "x >= 0", "y >= 0")
)
latte_max(
"-2 x + 3 y",
c("x + y <= 10", "x >= 0", "y >= 0"),
quiet = FALSE
)
df <- expand.grid("x" = 0:10, "y" = 0:10)
df <- subset(df, x + y <= 10L)
df$objective <- with(df, -2*x + 3*y)
library("ggplot2")
ggplot(df, aes(x, y, size = objective)) +
geom_point()
latte_min(
"-2 x + 3 y",
c("x + y <= 10", "x >= 0", "y >= 0"),
method = "cones"
)
latte_min("-2 x - 3 y - 4 z", c(
"3 x + 2 y + z <= 10",
"2 x + 5 y + 3 z <= 15",
"x >= 0", "y >= 0", "z >= 0"
), "cones", quiet = FALSE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.