Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  3-D Arrays

    Posted 03/26/09 05:38 AM

    Originally posted by: SystemAdmin


    [wam said:]

    I am trying to read in values to a 3-d array using concert. The arrays are defined as

    typedef IloArray<IloNumArray>    twoDMatrix;
    typedef IloArray< IloArray<IloNumArray> >  threeDMatrix;

    Since >> operator does not work to read in 3-d matrices directly, I've tried the following:

    const char* filename  = "./Discrete.dat";
    ifstream file(filename);
    threeDMatrix TimeMatrix(env,10);
    twoDMatrix WTime(env);
    for(i=0;i<10;i++){<br />        file >> WTime;
    TimeMatrix[i]=WTime;
    }

    The dat file contains data in the form:
    [[ 2-D matrix ]]
    [[ 2-D matrix ]]
    ...
    ...
    [[ last 2-D matrix ]]

    The program compiles and run, but the problem is that "TimeMatrix[i]" seems to points to the address of WTime and does not copy the value of the elements, i.e. after the loop has ended, all TimeMatrix[i] have the same value (the last of the 2-d matrix read from file).

    Could someone help me with this ?


     

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: 3-D Arrays

    Posted 03/31/09 12:30 AM

    Originally posted by: SystemAdmin


    [EdKlotz said:]

    I am trying to read in values to a 3-d array using concert. The arrays are defined as

    typedef IloArray<IloNumArray>    twoDMatrix;
    typedef IloArray< IloArray<IloNumArray> >  threeDMatrix;

    Since >> operator does not work to read in 3-d matrices directly, I've tried the following:

    const char* filename  = "./Discrete.dat";
    ifstream file(filename);
    threeDMatrix TimeMatrix(env,10);
    twoDMatrix WTime(env);
    for(i=0;i<10;i++){<br />        file >> WTime;
      TimeMatrix=WTime;
    }

    The dat file contains data in the form:
    [[ 2-D matrix ]]
    [[ 2-D matrix ]]
    ...
    ...
    [[ last 2-D matrix ]]

    The program compiles and run, but the problem is that "TimeMatrix" seems to points to the address of WTime and does not copy the value of the elements, i.e. after the loop has ended, all TimeMatrix have the same value (the last of the 2-d matrix read from file).

    Could someone help me with this ?

    TimeMatrix in the above loop is a single address.  So, your loop above just assigns new values to
    the same address with each pass.  You have declared TimeMatrix to be an array of 10 2 dimensional
    arrays.  Yet, you only have memory from one such two dimensional array.    In the loop, try calling
    TimeMatrix.add(Wtime).
    #CPLEXOptimizers
    #DecisionOptimization