Skip to content

interactions: "Quadratic expression are not supported" #444

@seschaub

Description

@seschaub

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions