question

Marian Cretu avatar image
0 Likes"
Marian Cretu asked Ben Wilson commented

Order "commonality" in Flexsim

Hello guys,

I have a list of orders in which the sku's are sorted ASC and put inside an array stored on a table.

Like this :



sku
order_1 (1,3,4,5,8)
order_2 (1,3,4)
order_3 (1,3,4,7)
order_4 (1,4,6,7)
order_5 (4,8,9)
order_6 (1,3,4,8)

Is there a way to build in Flexsim a function/algorithm that finds an order commonality array ?

For this example the function/algorithm should return (1,3,4).

Thanks.

FlexSim 20.1.0
flexsim 20.1.0orders
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi @marian.c2, was jordan.johnson's answer helpful? If so, please click the red "Accept" button on their answer. Or if you still have questions, add a comment and we'll continue the conversation.

0 Likes 0 ·

1 Answer

·
Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

Try something like this:

Table table = Table("GlobalTable1");
Array values;
Array counts;
for (int i = 1; i <= table.numRows; i++) {
    Array skus = table[i]["sku"];
    for (int j = 1; j <= skus.length; j++) {
        Variant value = skus[j];
        int index = values.indexOf(value);
        if (index <= 0) {
            counts[index] += 1;
        } else {
            values.push(value);
            counts.push(1);
        }
    }
}

Array result;
for (int i = 1; i <= values.length; i++) {
    if (counts[i] == table.numRows) {
        result.push(values[i]);
    }
}
return result;

The basic idea is to count the number of times each value occurs. Then, I make an array of the values that were on every row of the table (since their count is the same as the number of rows). However, this won't work if a sku can be in an order more than once. Also, I haven't run the code, so there might be some issues. But hopefully you get the idea.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.