R:定义优化问题构造函数OP(包ROI)的边界。 UseMethod出错(" as.V_bound")

时间:2017-04-28 11:29:04

标签: r optimization r-optimization

我想在使用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 )

但是,如果我手动添加边界&#34;&#34;我收到一个错误:

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"

但是描述说&#34;界限&#34;需要一个列表作为输入。

有没有人想过如何正确地将边界传递给OP函数?

1 个答案:

答案 0 :(得分:1)

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 )