r - 为什么我在 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)
解决方案
推荐阅读
- php - 如何使用 PhpStorm 配置 PHP 内置 Web 服务器
- php - 带有 PHP 的 ReCaptchaV2
- java - 使用 REST API 返回不同的 xml 响应 + Java
- c++ - 当您可以将所有内容都放在 .cpp 文件中时,为什么还要使用 .h 文件?
- c - 谁能解释这里如何使用 getchar 来输入数字序列?
- c# - 关于 VS 2013 的 Nuget 包管理器
- ruby-on-rails - 我的 Rails 应用程序中的 Anylogin 密钥要求错误
- java - 我的桌面应用程序无法使用 apache Oauth Client 调用 API 来获取令牌
- java - @JsonInclude(JsonInclude.Include.NON_EMPTY) 当我使用包装类并返回结果时不起作用
- r - 如何交替使用向量列表(正则表达式)