R:定义优化问题构造函数 OP(包 ROI)的界限。 UseMethod 错误("as.V_bound")
R: Defining bounds for Optimization Problem Constructor OP (package ROI). Error in UseMethod("as.V_bound")
我想在使用 ROI 包进行优化时定义变量的界限。我使用 OP 函数构造优化问题对象。
默认值是:下限等于零,上限等于+无穷大。
这是一个运行良好的示例代码:
LP <- OP( c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
max = TRUE )
但是如果我添加边界 "by hand" 我会得到一个错误:
LP <- OP( c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
bounds = list(upper=c(100,100,100), lower=c(0,0,0)),
max = TRUE )
Error in UseMethod("as.V_bound") :
no applicable method for 'as.V_bound' applied to an object of class "list"
但是描述说 "bounds" 需要一个列表作为输入。
有人知道如何将边界正确传递给 OP 函数吗?
LP <- OP(c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
bounds = V_bound(ui = seq_len(3), ub = rep.int(100, 3)),
maximum = TRUE )
我想在使用 ROI 包进行优化时定义变量的界限。我使用 OP 函数构造优化问题对象。
默认值是:下限等于零,上限等于+无穷大。
这是一个运行良好的示例代码:
LP <- OP( c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
max = TRUE )
但是如果我添加边界 "by hand" 我会得到一个错误:
LP <- OP( c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
bounds = list(upper=c(100,100,100), lower=c(0,0,0)),
max = TRUE )
Error in UseMethod("as.V_bound") :
no applicable method for 'as.V_bound' applied to an object of class "list"
但是描述说 "bounds" 需要一个列表作为输入。
有人知道如何将边界正确传递给 OP 函数吗?
LP <- OP(c(2, 4, 3),
L_constraint(L = matrix(c(3, 2, 1, 4, 1, 3, 2, 2, 2), nrow = 3),
dir = c("<=", "<=", "<="),
rhs = c(60, 40, 80)),
bounds = V_bound(ui = seq_len(3), ub = rep.int(100, 3)),
maximum = TRUE )