1

I created a Linear Programming model as follows:

require(lpSolveAPI)

% defining data

liab<--c(100,500,200,400,210,-600,100,900,500,400,600,810,100)
num_times<-length(liab)

% details the rates of interest

money <- 0.5/100;
shorttermrate <- 0.9/100;
creditgrate <- 1/100;
transactionrate <- 0.2/100;
bondvalue <- 200;

num_constraints = num_times;

% defining the no of variables

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)

% create an LP model with num_constraints constraints and % num_vars variables

lpmodel<-make.lp(num_constraints,num_vars)

% This is where I find an issue: % I am struggling to understand how to access elements within lpmodel. I get the error `Error in % 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
 }
}

Thanks

igauravsehrawat
  • 3,696
  • 3
  • 33
  • 46
user131983
  • 3,787
  • 4
  • 27
  • 42
  • The name of the package suggests one needs an additional package external to R. – IRTFM Sep 21 '14 at 17:47
  • I can't tell what you're trying to extract but the class `lpExtPtr` does not have subsetting operators (`[`) defined. It does have a bunch of `get.*` methods. Look at all the functions available with `help(package="lpSolveAPI")`. – MrFlick Sep 21 '14 at 19:15
  • @MrFlick Thanks for your answer. I was actually looking for a way to access a single element in each Vector. I checked the help documentation and there does not appear to be a way to do so. Would you have an idea how I could go about this? – user131983 Sep 22 '14 at 00:12
  • I still have no idea exactly what you want. In your test code, what value do you want to extract. If it worked properly, how could i test? – MrFlick Sep 22 '14 at 02:40

0 Answers0