次のように線形計画法モデルを作成しました。
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] のエラー: object of type 'externalptr' is not subsettable」というエラーが表示されます
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
}
}
ありがとう