R:'externalptr'类型的对象不是子集表问题

时间:2014-09-21 17:22:28

标签: r modeling linear-programming lpsolve

我创建了一个线性编程模型如下:

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约束创建LP模型 %num_vars变量

lpmodel<-make.lp(num_constraints,num_vars)

%这是我发现问题的地方: 我正在努力了解如何访问lpmodel中的元素。我收到错误`错误 %lpmodel [t,column - (ntimes - 1)+ t - 1]:type&#39; externalptr&#39;不是子集表格

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
 }
}

由于

0 个答案:

没有答案