Decision Optimization

Decision Optimization

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

 View Only
  • 1.  How to extract 3-D arrays (CPLEX + C++)

    Posted Tue January 01, 2013 10:35 AM

    Originally posted by: SystemAdmin


    Hello,

    I have one 2D and one 3D boolean arrays that I defined as:

    
    typedef IloArray<IloBoolVarArray> ArrayVar2D; typedef IloArray<IloArray<IloBoolVarArray> > ArrayVar3D;
    


    and

    
    IloEnv env; IloModel model(env); IloCplex cplex(env);
    


    and

    
    ArrayVar2D yir (env, 10); ArrayVar3D wijr (env, 10); 
    
    for (
    
    int a=0; a<10; a++) 
    { xij[a] = IloBoolVarArray(env, 10); yir[a] = IloBoolVarArray(env, 10); wijr[a] = ArrayVar2D(env, 10); 
    
    for (
    
    int b=0; b<10; b++) 
    { wijr[a][b] = IloBoolVarArray(env, 10); 
    } 
    }
    


    It compiles, and CPLEX solves the model. My Problem: when I try to get the values. The code:

    
    
    
    for (
    
    int b=0; b<10; b++) 
    { 
    
    for (
    
    int a=0; a<10; a++) 
    { cout << 
    "\t" << cplex.getValue(yir[b][a]); 
    } cout << endl; 
    }
    


    Works fine. But I couldn't get the results from the 3D matrix. The code:

    
    
    
    for (
    
    int c=0; c<10; c++) 
    { cout << 
    "c="<<c<<endl; 
    
    for (
    
    int b=0; b<10; b++) 
    { cout << 
    " "<<b; 
    
    for (
    
    int a=0; a<10; a++) 
    { cout << 
    "\t" << cplex.getValue(wijr[b][a][c]); 
    } cout << endl; 
    } 
    }
    


    Gives me:

    
    Error: IloExtractable 11 IloNumVarI has not been extracted by IloAlgorithm 0x9848ab0
    


    Does anyone have any idea?

    Thanks!!!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Sun January 06, 2013 12:34 PM

    Originally posted by: SystemAdmin


    This error occurs if you attempt to query the value of a variable that is not part of the model, i.e., the variable does not appear in the objective function or any constraint.
    You should double-check that all variables in the 3D array actually appear somewhere in the model.
    You can explicitly add the variables to the model:
    for (int c=0; c<10; c++) {
      for (int b=0; b<10; b++) {
        for (int a=0; a<10; a++) {
          model.add(wijr[b][a][b]);
        }
      }
    }
    

    When you do that you can query any of the variables in the 3D array and should no longer get that error.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Mon January 04, 2016 12:54 PM

    Originally posted by: m_adel


    Hi,

    I have a sort of similar problem with a 3d array. I would appreciate if you could give me a hint. I have defined my 3d array as follows:

     

    typedef IloArray<IloNumVarArray>  IloNumVarArray2;
    typedef IloArray<IloNumVarArray2>  IloNumVarArray3;  

     

    IloNumVarArray3 x2(env);
        for(ii=0;ii<SampSize;ii++){
                for (i = 0; i < N_Path; i++) {
                    x2[ii][i].add(IloNumVarArray(env,full_depth, 0.0,1.0,ILOINT));
            }
        }

     

    Then I get the following error:

    Unhandled exception at 0x00828680 in Simple Test.exe: 0xC0000005: Access violation at location 0x0000000000828680.

    I can see that the problem is related to the definition of my array but can not detect the problem with it. I would be thankful if you give me a hint.

    Thanks,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Tue January 05, 2016 01:54 AM

    The problem is that x2[ii] is never initialized. I think the correct initialization is this:

    IloNumVarArray3 x2(env);
    for(ii=0;ii<SampSize;ii++){
       x2.add(IloNumVarArray2(env));
       for (i = 0; i < N_Path; i++) {
          x2[ii].add(IloNumVarArray(env,full_depth, 0.0,1.0,ILOINT));
       }
    }
    

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Tue January 05, 2016 09:26 AM

    Originally posted by: m_adel


    Hi Daniel,

    Thank you so much I see your point. I solved it with another similar definition as bellow:

        IloNumVarArray3 x2(env,SampSize);
        for(ii=0;ii<SampSize;ii++){
            x2[ii]= IloNumVarArray2(env, N_Path);
            for (i = 0; i < N_Path; i++) {
                x2[ii][i]=IloNumVarArray(env,full_depth);
                for(j=0;j<full_depth;j++){
                    x2[ii][i][j]= IloNumVar(env, 0.0, 1.0, ILOINT);
                }
            }
        }
    

    Again many thanks for your answer.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Sat March 21, 2020 07:24 PM

    Originally posted by: Minoo


    Hi,

    I have a decision variable which is 3D like X_ijk. How can I add constraints related to this variable in the following ways?

    1- forall(p in i)
          {
             sum(q in j)sum(u in k)X[p][q][u] <= 1;      
          }

    2- forall(p in i, q in j)
          {
             sum(u in k)X[p][q][u] <= 1;      
          }

    3- forall(p in i, q in j, u in k)
          {
             X[p][q][u] <= 1;      
          }


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: How to extract 3-D arrays (CPLEX + C++)

    Posted Mon March 23, 2020 05:38 AM

    Hi


    range i=1..10;
    range j=1..5;
    range k=1..3;

    dvar boolean X[i][j][k];

    subject to
    {
    forall(p in i)
          {
             sum(q in j)sum(u in k)X[p][q][u] <= 1;      
          }

    //2-
    forall(p in i, q in j)
          {
             sum(u in k)X[p][q][u] <= 1;      
          }

    //3-
    forall(p in i, q in j, u in k)
          {
             X[p][q][u] <= 1;      
          }
          
        }     

    works fine

     

    regards

     

    https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer