我创建了一个线性规划模型,如下所示:
require(lpSolveAPI)
% 定义数据
liab<--c(100,500,200,400,210,-600,100,900,500,400,600,810,100)
num_times<-length(liab)
% 详细说明利率
money <- 0.5/100;
shorttermrate <- 0.9/100;
creditgrate <- 1/100;
transactionrate <- 0.2/100;
bondvalue <- 200;
num_constraints = num_times;
% 定义变量的数量
num_vars <- num_times-6;
num_vars <- num_vars + num_times-6;
num_vars <- num_vars + num_times-1;
num_vars <- num_vars + num_times-1;
num_vars <- num_vars + num_times-6;
num_vars <- num_vars + num_times-1;
vec1 <- c(2,3,4,5,6)
% 创建一个具有 num_constraints 约束和 % num_vars 变量的 LP 模型
lpmodel<-make.lp(num_constraints,num_vars)
% 这是我发现问题的地方: % 我正在努力理解如何访问lpmodel
. 我收到错误“% lpmodel[t, column - (ntimes - 1) + t - 1] 中的错误:'externalptr' 类型的对象不是子集
for (t in c(1:(num_times-6))){
if (t==1)
set.column(lpmodel,column+t,c(bondvalue), indices=c(t))
else
set.column(lpmodel,column+t,c((shorttermrate)*lpmodel[t-1,column]), indices=c(t)) % Issue associated with trying to access lpmodel
if (t==num_times-6)
set.column(lpmodel,column+t+1,c(-bondvalue), indices=c(t))
for (i in vec1){
set.column(lpmodel,column+t+i,c(lpmodel[t-1,column]-lpmodel[t,column]), indices=c(t)) % Issue associated with trying to access lpmodel
}
}
谢谢