Originally posted by: wzyryan
platform vs2010+cplex12.5+qt4.8.1
When I run my code, there is a probem. It says Unhandled exception at 0x7531b727 in ImageLoading.exe: Microsoft C++ exception: IloCplex::Exception at memory location 0x0043c62c.. I've been stuck here for a day. I list a part of my code below.
IloEnv env;
typedef IloArray<IloIntArray> IntMatrix;
IntMatrix mat(env, w);
for(IloInt i=0;i<w;i++){ //w=256,h=256
mat[i]=IloIntArray(env,h);
}
for(IloInt j=0;j<h;j++){
for(IloInt i=0;i<w;i++){
QRgb pixel=image->pixel(i,j);
IloInt r=qRed(pixel)*0.3;
IloInt g=qGreen(pixel)*0.59;
IloInt b=qBlue(pixel)*0.11;
mat[i][j]=r+g+b;
}
}
typedef IloArray<IloIntVarArray> IntVarMatrix;
IloInt i,j;
IloInt n=4;
IloInt width=64;
IloInt height=64;
IntVarMatrix hmat(env, width);
for(i=0;i<width;i++){
hmat[i]=IloIntVarArray(env,height,0,255);
}
typedef IloArray<IloNumExprArray> NumExprMatrix;
NumExprMatrix fmat(env, w);
for(i=0;i<w;i++){
fmat[i]=IloNumExprArray(env,h);
}
for(i=0;i<w;i++){ //initializing fmat[][]
for(j=0;j<h;j++){
fmat[i][j]=IloNumExpr(env);
}
}
IloModel model(env); //to construct a modeling object named model, within the environment env
IloIntVarArray t(env);
IloRangeArray c(env);
IloAnd and1(env);
IloAnd and2(env);
IloOr or(env);
t.add(IloIntVar(env,0,255));
t.add(IloIntVar(env,0,255));
c.add( t[0]-t[1]>=0 );
for(j=0;j<height;j++){
for(i=0;i<width;i++){ //big pixel
//IloInt count=0;
for(IloInt q=0;q<n;q++){
for(IloInt p=0;p<n;p++){ //small pixel
//for computing the light intensity
IloInt x,y,startx,starty,boundryx,boundryy;
if(j>=3){
starty=j-3;
}else{
starty=0;
}
if(i>=3){
startx=i-3;
}else{
startx=0;
}
if(j+3>height){
boundryy=height;
}else{
boundryy=j+3;
}
if(i+3>width){
boundryx=width;
}else{
boundryx=i+3;
}
for(y=starty;y<boundryy;y++){
for(x=startx;x<boundryx;x++){ //convolution range
if(((n*x+n/2-n*i-p)*(n*x+n/2-i*n-p)+(n*y+n/2-j*n-q)*(n*y+n/2-j*n-q))<=9*n*n){
fmat[n*i+p][n*j+q] += (hmat[x][y])*(qExp(-((x+1/2-i-(IloNum)p/n)*(x+1/2-i-(IloNum)p/n)+(y+1/2-j-(IloNum)q/n)*(y+1/2-j-(IloNum)q/n))/2))/6.28; //小像素点的光强的叠加计算
}
}
}
}
}
}
}
for(int p=0;p<256;p++){
for(int q=0;q<256;q++){
and1.add(mat[p][q] >= t[0]);
and1.add(fmat[p][q] >= t[0]);
and2.add(mat[p][q] <= t[1]);
and2.add(fmat[p][q] <= t[1]);
or.add(and1);
or.add(and2);
model.add(or);
}
}
model.add(c);
//IloObjective obj = IloMaximize(env,t[0]-t[1]);
model.add(IloMaximize(env, t[0]-t[1]));
//model.add(obj);
IloCplex cplex(model);
cplex.solve();
cout<<"Max="<<cplex.getObjValue();<<endl; //Here occurs the exception
//cplex.getStatus();
for(i=0;i<width;i++){
for(j=0;j<height;j++){
cout<<cplex.getValue(hmat[i][j])<<endl;
}
}
env.end();
I know that if I define an IloExpr expr(env), I have to end it using expr.end(). In my code, I define an IloNumExprArray fmat[][]. I wonder if it is because that I did not end this array.
#CPLEXOptimizers#DecisionOptimization