cplex - C++ valgrid error: Invalid read of size 8, Address 0x8 is not stack'd, malloc'd or (recently) free'd? -


i compiled code , ran it, gave me segmentation error.

so tested executable program using valgrid. got following message:

==7932== invalid read of size 8 ==7932==    @ 0x491840: iloexpr::operator+=(ilonumlinexprterm) (in /home/hna/g) ==7932==    0x43f261: main (in /home/hna/g) ==7932==  address 0x8 not stack'd, malloc'd or (recently) free'd ==7932==  ==7932==  ==7932== process terminating default action of signal 11 (sigsegv) ==7932==  access not within mapped region @ address 0x8 ==7932==    @ 0x491840: iloexpr::operator+=(ilonumlinexprterm) (in /home/hna/g) ==7932==    0x43f261: main (in /home/hna/g) ==7932==  if believe happened result of stack ==7932==  overflow in program's main thread (unlikely ==7932==  possible), can try increase size of ==7932==  main thread stack using --main-stacksize= flag. ==7932==  main thread stack size used in run 8388608. ==7932==  ==7932== heap summary: ==7932==     in use @ exit: 88,192 bytes in 55 blocks ==7932==   total heap usage: 56 allocs, 1 frees, 88,224 bytes allocated ==7932==  ==7932== leak summary: ==7932==    lost: 0 bytes in 0 blocks ==7932==    indirectly lost: 0 bytes in 0 blocks ==7932==      possibly lost: 0 bytes in 0 blocks ==7932==    still reachable: 88,192 bytes in 55 blocks ==7932==         suppressed: 0 bytes in 0 blocks ==7932== rerun --leak-check=full see details of leaked memory ==7932==  ==7932== counts of detected , suppressed errors, rerun with: -v ==7932== error summary: 1 errors 1 contexts (suppressed: 2 2) 

my code this. can me debug please? thank you!

int main() {       int m[8][8];    m[0][0] = 6; m[1][1] = 6; m[2][2] = 6; m[3][3] = 6;    m[0][4] = 4; m[1][4] = 4; m[2][5] = 4; m[3][5] = 4;    m[4][7] = 10; m[5][6] = 10;   iloenv env;  try { ilomodel model(env); int n = 4; int r = 2; int color = 5; int n = n*r; int addupto = 10;  iloarray<iloarray<ilonumvararray> > x(env, n);  //change intvararray 0~1 use getvalues  for(int i=0; i<n; i++) {     x[i] = iloarray<ilonumvararray> (env, n);     for(int j=0; j<n; j++) {         x[i][j] = ilonumvararray(env, color);         for(int k=0; k<color; k++) {             x[i][j][k] = ilonumvar(env, 0.0, 1.0, iloint);         }     } }   iloarray<iloarray<iloexpr> > sumofcolors(env, n);  for(int i=0; i<n; i++) {     sumofcolors[i] = iloarray<iloexpr>(env, n);     for(int j=0; j<n; j++) {         sumofcolors[i][j] = iloexpr(env);     } } for(int i=0; i<n; i++) {     for(int j=0; j<n; j++) {         for(int k=0; k<color; k++) {         sumofcolors[i][j] += x[i][j][k];         }     } }   iloarray<iloarray<ilorange> > range_sumofcolors = iloarray<iloarray<ilorange> >(env, n);  for(int i=0; i<n; i++) {     range_sumofcolors[i] = iloarray<ilorange> (env, n);     for(int j=0; j<n; j++) {         range_sumofcolors[i][j] = ilorange(env, 1, sumofcolors[i][j], 1);     } }   iloarray<iloarray<iloexpr> > weightedsumbr = iloarray<iloarray<iloexpr> >(env, r);  for(int i=0; i<r; i++) {     weightedsumbr[i] = iloarray<iloexpr>(env, r);     for(int j=0; j<color; j++) {         for(int k=i*n; k<(i+1)*n; k++) {             for(int l=0; l<n; l++) {                  weightedsumbr[i][j] += m[k][l]*x[k][l][j];             }         }     } }  iloarray<iloarray<ilorange> > range_weightedsumbr(env, r);  for(int i=0; i<r; i++) {     range_weightedsumbr[i] = iloarray<ilorange>(env, r);     for(int j=0; j<color; j++) {         range_weightedsumbr[i][j] = ilorange(env, 0, weightedsumbr[i][j], addupto);     } }   iloarray<iloarray<iloexpr> > weightedsumbc(env, r);  for(int i=0; i<r; i++) {      weightedsumbc[i] = iloarray<iloexpr>(env, r);      for(int j=0; j<color; j++) {          for(int k=0; k<n; k++) {              for(int l=i*n; l<(i+1)*n; l++) {                  weightedsumbc[i][j] += m[k][l]*x[k][l][j];              }          }      } }   iloarray<iloarray<ilorange> > range_weightedsumbc(env, r);  for(int i=0; i<r; i++) {     range_weightedsumbc[i] = iloarray<ilorange>(env, r);      for(int j=0; j<color; j++) {         range_weightedsumbc[i][j] = ilorange(env, 0, weightedsumbc[i][j], addupto);     } }  for(int i=0; i<n; i++) {     for(int j=0; j<n; j++) {         model.add(range_sumofcolors[i][j]);     } }  for(int i=0; i<r; i++) {     for(int j=0; j<color; j++) {         model.add(range_weightedsumbr[i][j]);         model.add(range_weightedsumbc[i][j]);     } }  ilocplex cplex(env); cplex.extract(model); cplex.solve(); cplex.out() << "solution status = " << cplex.getstatus() << endl; cplex.out() << endl;    iloarray<iloarray<ilonumarray> > xcp (env, n);  //change intvararray 0~1 use getvalues  for(int i=0; i<n; i++) {     xcp[i] = iloarray<ilonumarray> (env, n);     for(int j=0; j<n; j++) {         xcp[i][j] = ilonumarray(env, color);         for(int k=0; k<color; k++) {             xcp[i][j][k] = ilonum(env, 0.0, 1.0, iloint);         }     } }       for(int i=0; i<n; i++) {         for(int j=0; j<n; j++) {             cplex.out() << cplex.getvalues(x[i][j], xcp[i][j]) << endl;         }     }       if (cplex.getstatus() == iloalgorithm::infeasible){         //    cplex.out() << endl << "*** model not infeasible ***" << endl;          ofstream outdata;          outdata.open("badmatrix.csv");         if (!outdata){cerr << "error: file not opened" << endl;             exit(1);}         else{             size_t it1;             size_t it2;             size_t n = 8; //m.size();             (it1=0;it1<n;it1++){                 (it2 = 0; it2<n; it2++){                     outdata << matr[it1][it2] << endl;}}           }         outdata.close();         env.end();         cplex.out() << "infeasible matrix detected" << endl;         return 1;     } } catch(iloexception& e) {     cerr << " error: " << e << endl; } catch(...) {     cerr << " error: " << endl; } env.end(); return 0; } 

weightedsumbc[][] has both indices defined range on r, j goes color

so change:

 weightedsumbc[i] = iloarray<iloexpr>(env, r); 

to:

 weightedsumbc[i] = iloarray<iloexpr>(env, color); 

similar problem here:

for(int i=0; i<r; i++) {     range_weightedsumbc[i] = iloarray<ilorange>(env, r);      for(int j=0; j<color; j++) {         range_weightedsumbc[i][j] = ilorange(env, 0, weightedsumbc[i][j], addupto);     } } 

change to:

range_weightedsumbc[i] = iloarray<ilorange>(env, color);  

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -