首页 > 解决方案 > 为什么我在 R 中遇到这个错误以进行优化?“您的环境中有一些变量会干扰您定义的模型变量:x,y”

问题描述

大家好,我正在尝试运行属于Here的代码,但出现此错误:

"There are variables in your environment that interfere with your defined model variables: x,y. This can lead to unexpected behavior."

为什么会这样?

library(dplyr)
library(ROI)
library(ROI.plugin.glpk)
library(ompr)
library(ompr.roi)

result <- MIPModel() %>%
  add_variable(x, type = "integer") %>%
  add_variable(y, type = "continuous", lb = 0) %>%
  set_bounds(x, lb = 0) %>%
  set_objective(x + y, "max") %>%
  add_constraint(x + y <= 11.25) %>%
  solve_model(with_ROI(solver = "glpk")) 
get_solution(result, x)
get_solution(result, y)

标签: roptimization

解决方案


推荐阅读