我正在尝试运行这个模型。我正在尝试最大化:x[4]
w.r.t Mv = c(0,0,0,0)
lb < v < ub
但我有两个问题,第一个矩阵乘法。
library(ompr)
lb <- c(-200, 0, -200, -200)
ub <- c(1000, 1000, 1000, 1000)
M <- matrix(rbind(
c(-1, 0, -1, 0), # A
c(-1, 0, 0, -2), # B
c(1, -2, 0, 0), # C
c(1, 0, 0, 2), # D
c(0, 2, -1, 0), # E
c(0, 0, 1, -1) # F
), nrow = 6)
n <- 4
rhs <- rep(0, n)
model <- MIPModel() %>%
add_variable(x[i], i = 1:n, type = "continuous") %>%
set_objective(x[4]) %>%
add_constraint(M[i, ] %*% x == rhs[i], i = 1:n)
我收到以下错误。
M[i, ] %*% x 中的错误:需要数字/复数矩阵/向量参数
其次,我试图以矢量化的方式设置边界,但我不知道该怎么做。我尝试了以下方法:
set_bounds(x[i], ub = ub[i], lb = lb[i], i = 1:n)
这给出了:
找不到对象“我”
任何帮助都会非常有用!