Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Variable definition with exception

    Posted 05/08/12 08:45 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hi

    If I have variable with three indices (let say X_opt) is not defined or not exist when o=p, I defined the variables as in the following code and I used if-continue statement to exclude the definition when o=p.

    I didn't receive any error, but when I print the results with using same if-continue statement to exclude the o=p variables, I receive an segmentation fault

    Is what I did correct or not and is there any other method to exclude some variable definitions.
    IloNumVarArray3 X_opt(env,nbWoundedCat);
    for( o = 0; o < nbWoundedCat; o++)
    {
    X_opt[o] = IloNumVarArray2 (env, nbNodes);
     
    for( p=0; p<nbNodes; p++)
    {
    if (o==p) {continue;}
    X_hopt[o][p] = IloNumVarArray (env, nbTimes);}}
    


    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Variable definition with exception

    Posted 05/09/12 07:07 AM

    Originally posted by: SystemAdmin


    I take it you initialize the elements 'X_opt[o][p][i]' in some other place? If not then all the handles in the array will be empty, see the reference documentation for IloNumVarArray(const IloEnv,IloInt), the constructor you use in your innermost loop.
    The test of your code looks good to me at first glance.
    Maybe there is a problem with the code that prints the results? Could you show us this code as well?
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Variable definition with exception

    Posted 05/09/12 12:10 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hi, Thanks Daniel

    I forget to show the limits in my example, the definition at inner most loop is
    X-opt[o][p] = IloNumVarArray (env, curr_t,  0.0, IloInfinity);
    


    not
    X-opt[o][p] = IloNumVarArray (env, curr_t);
    


    The output print is:
    env.out() << "X_opt: " << endl;
          
            for (o=0; o<nbNodes; o++){
                    for(p=0; p<nbNodes; p++){
                       if (o=p) {continue;}
                            for (t=0; t<nbTimes; t++){
             env.out() << "X_opt[" << o << "] "<< "["<< p << "] "<< "["<< t << "] " << cplex.getValue(X_hopt[o][p][t]) << endl;}}}
    


    Use this, could you figure out where is the problem?

    Thanks
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Variable definition with exception

    Posted 05/10/12 04:23 AM

    Originally posted by: SystemAdmin


    Does the exception occur for all combinations of o/p/t or only for some special combinations? If it only occurs for special combinations, what are the combinations for which the exception occurs?

    Does it work if you replace
    env.out() << "X_opt[" << o << "] "<< "["<< p << "] "<< "["<< t << "] " << cplex.getValue(X_hopt[o][p][t]) << endl;
    

    by
    env.out() << "X_opt[" << o << "] "<< "["<< p << "] "<< "["<< t << "] " << X_hopt[o][p][t] << endl;
    

    (i.e., only print the variable, not its value). If so, what is the output of that?
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Variable definition with exception

    Posted 05/10/12 12:54 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Hi, Daniel

    I figure out where is the problem. In previous I use for loops without using {}

    Just I use { after each for, and }}} at the end of loops and it is working well now

    Thanks for your help
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Variable definition with exception

    Posted 05/09/12 12:16 PM

    Originally posted by: FANS_Nader_Al_Theeb


    Sorry, I have other mistake in my replay. In the if-statment:

    if (o==p) {continue;}
    


    not

    if (o=p) {continue;}
    

    #CPLEXOptimizers
    #DecisionOptimization