Question

I have just started to use cplex library and get stuck in defining IloExprArray in my code. Here is my snippet of code:

IloExprArray diff;
diff= IloExprArray(iloEnv,list.size());
for( int i=1; i<=10; i++ ) {
    for( int j=0; j<9; j++ ) {
         double weight = globalObjects->value.at(j)->getmyproperty(i);

         diff[j] += ( Ycfg[i][j]*Ycfg[i][j] - 2*weight*Ycfg[i][j] + weight*weight );
//where Ycfg is IloArray<IloNumVarArray>

    }
}   

But whenever i am running this code it get stuck at diff[j] += .. line. I also searched on net but didn't get good documentation except of official one. Another question What about if i use IloArray <IloExpr> instead of IloExprArray ?

Was it helpful?

Solution

Your initialization code

diff = IloExprArray(iloEnv, list.size())

creates an array of empty handles. Handles are essentially ILOG's smart pointers. When you do a += on an empty handle, you are essentially doing it on a null pointer. You need to initialize all the handles.

for (int i = 0; i < list.size(); ++i)
     diff[i] = IloExpr(iloEnv);

There are other suspicious parts of your code that could be causing you trouble. For example, the outer for-loop runs from 1 to 10, and you use list.size() as the length of diff, but your is for (j = 0; j< 9; ++j) instead of for (j = 0; j < list.size(); ++j)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top