Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Dynamic Array of variable lengths

    Posted 10/28/16 02:23 AM

    Originally posted by: CPlex_NooBie


    Greetings!

    I am working on a problem where I need a variable size matrix. For example Row 1 might have 3 Columns, Row 2 has 5 Columns and Row 3 has 6 columns. So I created a matrix of 3x6 since the max length is 6 and using the required lengths. But is there a way to create a dynamic array? 
    Thanks.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Dynamic Array of variable lengths

    Posted 10/28/16 02:46 AM

    Hi,

    you could use a tuple set instead.

    tuple t

    {

      int column;

      int row;

      int value;

    };

    and then you do not have to book more memory than what you need and you may grow your array.

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Dynamic Array of variable lengths

    Posted 11/14/16 07:43 AM

    Originally posted by: Anatu


    hi

    i have a similar problem so im joining your conversation, thanks Smile

     

    how do i initialize such a tuple set? since a tuple set cannot be initialized with a range?

    lets say i already have an array of the lengths:

      int rows [nb in nbOfColumns];

    after i declare the tuple like you suggested, how do i continue so that the tupleset will contain the row, the column index and the value for each index?

     

    thank you


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Dynamic Array of variable lengths

    Posted 11/14/16 08:09 AM

    Hi,

    let me add a small example:

    range nbOfColumns=1..4;

    int rows [nb in nbOfColumns]=nb;

    tuple t
    {
          int column;
          int row;
          int value;
        };
        
        
    {t} s={<col,row,row*col> | col in nbOfColumns,row in 1..rows[col] };   

    execute
    {
    writeln(s);
    }

    which gives

     

     {<1 1 1> <2 1 2> <2 2 4> <3 1 3> <3 2 6> <3 3 9> <4 1 4>
         <4 2 8> <4 3 12> <4 4 16>}

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer