0

我正在尝试重现 ROI 创建者给出的一些示例。

例如,在http://statmath.wu.ac.at/courses/optimization/Presentations/ROI-2011.pdf(幻灯片 15-17)中有一个例子:

library("ROI")
#ROI: R Optimization Infrastructure
#Installed solver plugins: cplex, lpsolve, glpk, quadprog, symphony, nlminb.
#Default solver: glpk.

(constr1 <- L_constraint(c(1, 2), "<", 4))
#An object containing 1 linear constraints.

(constr2 <- L_constraint(matrix(c(1:4), ncol = 2), c("<", "<"), c(4, 5)))
#An object containing 2 linear constraints.

rbind(constr1, constr2)
#An object containing 3 linear constraints.

(constr3 <- Q_constraint(matrix(rep(2, 4), ncol = 2), c(1, 2), "<", 5))
#An object containing 1 constraints.
#Some constraints are of type quadratic.

foo <- function(x) {sum(x^3) - seq_along(x) %*% x}

F_constraint(foo, "<", 5)

lp <- LP(objective = 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)), maximum = TRUE)

qp <- QP(Q_objective(Q = diag(1, 3), L = c(0, -5, 0)), L_constraint(L =    matrix(c(-4, -3, 0, 2, 1, 0, 0, -2, 1), ncol = 3, byrow = TRUE), dir = rep(">=", 3), rhs = c(-8, 2, 0)))

当我运行它时,我得到了错误

Error in LP(objective = c(2, 4, 3), L_constraint(L = matrix(c(3, 2, 1,  : 
  could not find function "LP"

Error in QP(Q_objective(Q = diag(1, 3), L = c(0, -5, 0)), L_constraint(L = matrix(c(-4,  : 
  could not find function "QP"   

事实上,这些函数不在 ROI 的命名空间中。例如

ROI::LP
Error: 'LP' is not an exported object from 'namespace:ROI'

我在网上找到的其他示例中出现了相同的语法,但从未定义函数 LP 和 QP。

我正在使用 ROI 0.3.0

有人可以告诉我出了什么问题吗?

4

1 回答 1

0

命令LPQP都更改为OP.

library("ROI")
## ROI: R Optimization Infrastructure
## Registered solver plugins: nlminb, alabama, cbc, cccp, clp, deoptim, ecos, glpk, ipop, lpsolve, msbinlp, neos, nloptr, ucminf, spg, cgm, vmm, bobyqa, newuoa, uobyqa, hjk, nmk, lbfgs, optimx, qpoases, quadprog, scs, symphony.
## Default solver: auto.

(constr1 <- L_constraint(c(1, 2), "<", 4))
## An object containing 1 linear constraint.

(constr2 <- L_constraint(matrix(c(1:4), ncol = 2), c("<", "<"), c(4, 5)))
## An object containing 2 linear constraints.

rbind(constr1, constr2)
## An object containing 3 linear constraints.

(constr3 <- Q_constraint(matrix(rep(2, 4), ncol = 2), c(1, 2), "<", 5))
## An object containing 0 linear constraints
##                      1 quadratic constraint.

foo <- function(x) {sum(x^3) - seq_along(x) %*% x}
F_constraint(foo, "<", 5)
## An object containing 1 nonlinear constraint.

lp <- OP(objective = 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)), maximum = TRUE)

qp <- OP(Q_objective(Q = diag(1, 3), L = c(0, -5, 0)), 
         L_constraint(L =    matrix(c(-4, -3, 0, 2, 1, 0, 0, -2, 1), ncol = 3, byrow = TRUE), 
                      dir = rep(">=", 3), rhs = c(-8, 2, 0)))
于 2019-03-03T22:59:08.077 回答