Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  ordering values in tables

    Posted 07/30/08 06:47 PM

    Originally posted by: SystemAdmin


    [bagrund said:]

    I've got a table of data - 2-dimensional-array - and I'm trying to find the next higher value (or if there is no higher value the function should return the highest value in the column) in the column for each cell.
    I tried to use the min-function with the restriction that the result has to be higher than the source data but it doesn't work.

    Is there an easy way to solve this problem?
    Thanks for helping

    example:
    [table][tr][td]5[/td][td]4[/td][td]2[/td][td][/td][td]5[/td][td]6[/td][td]4[/td][/tr][tr][td]3[/td][td]6[/td][td]9[/td][td]->[/td][td]5[/td][td]8[/td][td]9[/td][/tr][tr][td]1[/td][td]8[/td][td]4[/td][td][/td][td]3[/td][td]8[/td][td]9[/td][/tr][/table]
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: ordering values in tables

    Posted 07/30/08 08:57 PM

    Originally posted by: SystemAdmin


    [UDOPS said:]

    I think you need to split this all up into ordered sets and then use the next() function to get the next higher value. I guess it will require an indexed ordered set for each column, using the "sorted" directive. Also, when you say "maximum if there is no higher", then you mean the existing value, no change, correct?
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: ordering values in tables

    Posted 07/31/08 11:51 AM

    Originally posted by: SystemAdmin


    [bagrund said:]

    Thats right, I'll save the existing value if there is no higher one.
    "indexed ordered set for each column" means I split up the table--> order --> look for the position of the old value --> take the next one and copy it to the new "table-array"?!
    And how do I split up the array:

    int A[x,y] = [[5,4,2],[3,6,9],[1,8,4]];

    now, I've to define a new set:

    int B[y] =

    but what is the command to take all values out of column y ?

    Thanks for your patience!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: ordering values in tables

    Posted 07/31/08 10:09 PM

    Originally posted by: SystemAdmin


    [UDOPS said:]

    I think you need to create 3 single dimension ordered sets, AA, XX, and YY, then you need to have an execute statement that iterates through all values of A[x][y] and creates a new array, say B[x1][y1], whose values are found by referencing the position of each value in the ordered sets and retrieving the next member. This might actually be easier if instead you make a tuple set {<A, X, Y>} and iterate over that. Do you want the result to contain the same number of elements as the source? They you better add a serial number column (key), because some of the results may be duplicates and the result will be a shorter set.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: ordering values in tables

    Posted 08/01/08 12:17 AM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    The following code works fine. It could probably be enhanced. I just collect and sort for each cell the collection of numbers greater than the cell in its column. Then, if the collection is a singleton, we are in your particular case (the cell is the highest number in the column), otherwise the collection size is at least two elements, therefore the number we look for is the second one : item(...,1)

    range rows = 1..3;
    range cols = 1..3;

    int data[rows][cols] = [ [5,4,2], [3, 6, 9], [1, 8, 4] ];
    sorted {int} s[r in rows][c in cols] = { data[r2][c] | r2 in rows : data[r2][c]>=data[r][c]};

    int result[r in rows][c in cols] = (card(s[r][c])==1)?data[r][c]:item(s[r][c],1); 

    execute
    {
    writeln(result);
    }

    David Gravot
    ROSTUDEL Operations Research
    www.rostudel.com
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: ordering values in tables

    Posted 08/01/08 01:09 PM

    Originally posted by: SystemAdmin


    [bagrund said:]

    Brilliant, that's exactly what I'm looking for and I didn't know some of the expressions you used to solve the problem. Thanks a lot!

    But there is still a little question about the sorted-function:
    if there are multiple entries with the same value, does sorted delete the duplicates? I think "data[r2][c]>=data[r][c]" collects also the equal values (that's what I'm looking for: if there are two identical entries the mechanism should choose this value for the result-array) but it's not assigned to the result.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: ordering values in tables

    Posted 08/05/08 10:02 PM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    Remember that the collection has no duplicate, e.g declaring a set of integers as {int} mySet = {3,3,5} creates actually the set {3,5}. So if there are duplicate in the column (let's figure the column is the transpose of [3 3 5]), my model would return the transpose of [5 5 5]. I don't know if it is correct since I don't know precisely if, according to your requirement,  the "next higher value" of any of the "3" should be 5 or again 3 since 3 is duplicated. In this latter case, we should slightly modify the model.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: ordering values in tables

    Posted 08/05/08 10:02 PM

    Originally posted by: SystemAdmin


    [bagrund said:]

    I misdesribed the requirement. My intention was the latter case.
    If there are duplicate entries, the function should return this one. If there isn't a duplicate the function should return the next higher one.
    Sorry for the confusion.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: ordering values in tables

    Posted 08/07/08 03:14 AM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    Well, then the result should be the value of the cell itself when
    . either this value is the highest value (that was implemented in the model shown in one of my previous post)
    . or this value is duplicated (*)

    otherwise, we take the next higher value (also already implemented in the previous model)

    To modify the model to address (*) , we can just define :
    int occur[r in rows][c in cols] = count(all(r2 in rows) data[r2][c], data[r][c]);

    and modify result as :
    int result[r in rows][c in cols] = (card(s[r][c])==1 || occur[r][c]>1)?data[r][c]:item(s[r][c],1);

    Indeed, by definition of "occur" , it counts the number of occurrences of the value of the cell data[r][c] in the column c of the matrix data.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: ordering values in tables

    Posted 08/11/08 08:53 PM

    Originally posted by: SystemAdmin


    [bagrund said:]

    Fits with the example, thank you!
    In my special case I had to switch the data from int to float. The syntax of the count-function needs integer values.
    Could you suggest any workarounds?
    Thank you again!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: ordering values in tables

    Posted 08/21/08 05:53 PM

    Originally posted by: SystemAdmin


    [dgravot@noos.fr said:]

    Using float data, you can mimic the count function with counting the cardinality of the same collection :

    int occur[r in rows][c in cols] = card({r2 | r2 in rows : data[r2][c]==data[r][c] });
    #DecisionOptimization
    #OPLusingCPLEXOptimizer