Optmizing r to java call in rserve
<p>I am facing a problem while performing optimization using lpSolveAPI in R and Java on a large dataset.</p>

<p>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.</p>

<p>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.</p>

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

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

<p>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.</p>

<pre><code>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");
    }
}
</code></pre>