简体   繁体   English

将ROI称为“ LP”和“ QP”功能

[英]Calling ROI “LP ”and “QP” functions

I am trying to reproduce some of the examples given by the ROI creators. 我正在尝试重现ROI创建者提供的一些示例。

For example in http://statmath.wu.ac.at/courses/optimization/Presentations/ROI-2011.pdf (slides 15-17) there is the example: 例如,在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)))

When I run it I get the errors 当我运行它时,我得到了错误

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

and

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"   

In fact the functions are not in ROI's namespace. 实际上,这些功能不在ROI的命名空间中。 eg 例如

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

The same syntax appears in other examples I found on the web but the functions LP and QP are never defined. 我在网上找到的其他示例中也出现了相同的语法,但是从未定义函数LP和QP。

I am using ROI 0.3.0 我正在使用ROI 0.3.0

Can someone tell me what is going wrong? 有人可以告诉我怎么了吗?

The commands LP and QP were both changed to OP . 命令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)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM