Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
3 replies Latest Post - ‏2013-03-12T07:16:50Z by SystemAdmin
SystemAdmin
SystemAdmin
7929 Posts
ACCEPTED ANSWER

Pinned topic Concert Tech C++ - IloRanage Runtime error

‏2013-03-12T02:45:28Z |
Hi all,

This runtime error has been bugging me for almost a week! so devastated;( Currently working on a simulation with Cplex for one-step optimization, and kinda urgent.But i am a beginner in Cplex. All these errors popping up are becoming irksome. Thought I could use your help!

The program stops at the statement:

range[i].add(IloRange(env, lower_bound, FREQ_LVL_PER_CPU*(n[i][j]-1) + fl[i][j], upper_bound, 
"range"));

Daniel here indicated that it might be array initialization problem. All IloIntVars are provided with upper and lower bounds when added to an instance of IloIntVarArray. But no specific values are assigned to the variables. Is that where the problem is? so lost...

I attached the complete code as below:


//CPLEX Environment IloEnv env; IloModel model(env, 
"resalloc"); 
//CPlex cplex =  new CPlex();   IloIntVarArray n[APP_NUM]; IloIntVarArray fl[APP_NUM]; 

for(

int i = 0; i < APP_NUM; i++)
{ n[i] = IloIntVarArray(env, application[i].hosting_server_num); fl[i] = IloIntVarArray(env, application[i].hosting_server_num); 

for(

int j = 0; j < application[i].hosting_server_num; j++)
{ n[i].add(IloIntVar(env, 1, CPU_CAP_PER_APP, 
"number")); fl[i].add(IloIntVar(env, 1, FREQ_LVL_PER_CPU, 
"freq_level")); 
} 
} IloRangeArray range[APP_NUM]; 

for(

int i = 0; i < APP_NUM; i++)
{ 

for(

int j = 0; j < application[i].hosting_server_num; j++)
{ IloInt lower_bound =  1; IloInt upper_bound =  10; range[i].add(IloRange(env, lower_bound, FREQ_LVL_PER_CPU*(n[i][j]-1) + fl[i][j], upper_bound, 
"range")); 
//this is where the access violation error occurs. 
} model.add(range[i]); 
} env.end();


All capitalized variables are global and constant.

Any help would be deeply appreciated! Thanks in advance!
Updated on 2013-03-12T07:16:50Z at 2013-03-12T07:16:50Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7929 Posts
    ACCEPTED ANSWER

    Re: Concert Tech C++ - IloRanage Runtime error

    ‏2013-03-12T06:49:54Z  in response to SystemAdmin
    Well, it is an initialization problem (actually two of them).
    The first problem is this:
    
    n[i] = IloIntVarArray(env, application[i].hosting_server_num); fl[i] = IloIntVarArray(env, application[i].hosting_server_num); 
    
    for(
    
    int j = 0; j < application[i].hosting_server_num; j++)
    { n[i].add(IloIntVar(env, 1, CPU_CAP_PER_APP, 
    "number")); fl[i].add(IloIntVar(env, 1, FREQ_LVL_PER_CPU, 
    "freq_level")); 
    }
    

    The arrays n and fl are initialized to hosting_server_num elements. Each element is an empty (uninitialized) IloIntVar instance.
    The loop over j appends to those arrays. This means the arrays will have length 2*hosting_server_num after the loop and only the second half of the variables will be initialized. There are two ways to fix that up:
    1. Don't initialize the arrays with a length:
    
    n[i] = IloIntVarArray(env); fl[i] = IloIntVarArray(env);
    

    2. Assign to the array elements instead of appending to the arrays:
    
    n[i][j] = IloIntVar(env, 1, CPU_CAP_PER_APP, 
    "number"); fl[i][j] = IloIntVar(env, 1, FREQ_LVL_PER_CPU, 
    "freq_level");
    

    Notice that all your variables have the same name here. This will not help in debugging and will cause major trouble if you ever export your problem to a human-readable file format (LP, MPS).

    Once the problem above is fixed you will bump into the next access violation in the same line.
    This access violation happens because the elements in range are never initialized. The beginning of the second loop should have a statement like
    
    range[i] = IloRangeArray(env);
    

    With that added your code runs here without trouble.
    • SystemAdmin
      SystemAdmin
      7929 Posts
      ACCEPTED ANSWER

      Re: Concert Tech C++ - IloRanage Runtime error

      ‏2013-03-12T07:15:59Z  in response to SystemAdmin
      Thanks Daniel! You are my life saver! Millions of thanks;)
  • SystemAdmin
    SystemAdmin
    7929 Posts
    ACCEPTED ANSWER

    Re: Concert Tech C++ - IloRanage Runtime error

    ‏2013-03-12T07:16:50Z  in response to SystemAdmin
    Never forget to initialize arrays you created!