Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  What is wrong with this 3D variable array definition?

    Posted 08/03/12 08:40 AM

    Originally posted by: hllsen


    To use in a MIP model, I created 3D variable X_{k,j,t} with sizes n, m and H, respectively. Type definition and initialization is like this:
    
    typedef IloArray<IloArray<IloNumVarArray > >     IloNumVarArray3; IloNumVarArray3 X( env );
    

    Then array is filled like this:
    
    X.add( m, IloArray<IloNumVarArray >( env ) ); 
    
    for (k = 0; k < m; ++k ) X[k].add( n, IloNumVarArray( env, H, 0, IloInfinity, IloNumVar::Float ));
    

    After considerable amount of debugging time, I noticed that this method does not create n*m*H number of variables. That is, "id" of different k or j index variables has the same "id". Therefore, I ended up with only H number of variables.

    Variable id
    X[0][0][0] 1
    X[0][1][0] 1
    X[1][2][0] 1
    X[0][0][1] 2
    X[0][1][1] 2
    X[1][2][1] 2

    But, the code below just works fine and creates n*m*H number of variables.
    
    
    
    for (k = 0; k < m; ++k ) 
    { X.add( IloArray<IloNumVarArray >( env ) ); 
    
    for (j = 0; j < n; ++j) 
    { X[k].add( IloNumVarArray( env, H, 0, IloInfinity, IloNumVar::Float ) ); 
    } 
    }
    


    AFAIK, my problem is solved but I still couldn't quite understand why first method does not work. An explanation would be very much appreciated. Thank you.
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: What is wrong with this 3D variable array definition?

    Posted 08/03/12 06:27 PM

    Originally posted by: SystemAdmin


    > hllsen wrote:

    >
    > X.add( m, IloArray<IloNumVarArray >( env ) );
    >
    


    I think what this is doing is creating one 2D array and adding that one array m times -- meaning all m entries are pointers to the same array. The C++ manual says that the overload of add() you are using adds the same second argument m times. The constructor in the second argument is only called once.

    Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: What is wrong with this 3D variable array definition?

    Posted 08/08/12 01:33 PM

    Originally posted by: hllsen


    Thanks for the clarification Paul...
    #CPLEXOptimizers
    #DecisionOptimization