-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interactions: "Quadratic expression are not supported" #444
Comments
Hi, first off, big thank you for developing this library. I'm running into the same issue but it may be that I'm setting up something incorrectly. Here is a reproducible example: `x <- c(1, 2, 3, 4, 5) m <- length(x) model <- MIPModel() %>% Update: I reformulated my code to work, seems that I didn't need to add x & y: X <- c(1, 2, 3, 4, 5) x <- length(X) model <- MIPModel() %>% |
The ompr documentation does not suggest a non-linear optimization capability. However the R ROI package allows the formulation of non-linear models: http://roi.r-forge.r-project.org/index.html |
Yes quadratic terms are not supported. It wouldn't be too much work though to add them at this point. Right now though I don't have a lot of time. The infrastructure is there. rmpk supports it. |
dear all,
first of all, thank you Drik for creating and maintaining the package.
Today, I was trying to solve a model with "interaction terms". However, I received an error message: "Quadratic expression are not supported"
Bellow, you find a simplified version of the model. In this model the interaction is "* (1 + x[i])".
Does someone know how to solve this? do i simply miss something?
define parameters
soil_coef <- c(2, -1)
manage_coef <- c(0.5, -.1)
number of plots
n = 100
information about land properties
dz <- data.frame(
soil = runif(n, min = 5, max = 10))
cov.mat_me <- dz %>% as.matrix()
model definition
model_1 <- MIPModel() %>%
define variable that we optimize over
add_variable(x[i], i = 1:n, type = "binary") |>
set objective function
set_objective(
sum_over(
# output 1
(as.numeric(cov.mat_me[i,1]) * soil_coef[1] + x[i] * manage_coef[1] ) * (1 + x[i]) +
# output 2
(as.numeric(cov.mat_me[i,1]) * soil_coef[1] + x[i] * manage_coef[1]) * (1 + x[i]),
i = 1:n),
"max") |>
add the constraint
add_constraint(sum_over(x[i], i = 1:n) <= 5 ) %>%
solve_model(with_ROI(solver = "glpk")) |>
get_solution(x[i])
model_1
The text was updated successfully, but these errors were encountered: