Optimizing java to R call in Rserve

#1
I am facing a problem while performing optimization using lpSolveAPI in R and Java on a large dataset.

I tried Rserve,RCaller,JRI,Renjin and found that Rserve is what actually suits my need. RCaller has a functionality that has allows to run all the r commands as a batch, but after that the context is lost.In Renjin the lpSolveAPI support is still under development.I also tried Rglpk package in R but the tuning options provided are limited compared to Rglpk.

The loop which is taking a lot of time is as shared below, the eval and assign statements are taking up a majority of run time.

The number of times the loop1 repeats is 300 - more than 3000, similarly loop2 & loop3(depends on input ).

The assign and eval statements cannot be avoided as it is part of the logic.

Is there something to boost the performance of this loop, or another library to be used so that the code can be evaluated after the loop is completed(kind of a batch run). Just to get an idea of things – the program with an input of 1000 records completes in 3hrs, and an input of 2000 records is taking more than a day and is getting stuck not sure if it will complete.

for( : loop1){
for ( : loop2) {
rconn.assign("constraint");
if ( condition ){
rconn.voidEval("constraint");
}else{
rconn.assign("constraint");
}
if( condition ){
rconn.voidEval("constraint");
}else{
rconn.voidEval("constraint");
}
}
for( : loop3) {
rconn.assign("constraint");
if ( condition ){
rconn.voidEval("constraint");
}else{
rconn.assign("constraint");
}
if(condition){
rconn.voidEval("constraint");
}else{
rconn.voidEval("constraint");
}
rconn.eval("constraint").asStrings();
}
for (String[] item : map.values()){
rconn.assign("constraint",item);
rconn.voidEval("constraint");
}
}



This is very critical to our business and would like to hear from you asap.