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.

1 Answer

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

Try something like this:

  1. Table table = Table("GlobalTable1");
  2. Array values;
  3. Array counts;
  4. for (int i = 1; i <= table.numRows; i++) {
  5. Array skus = table[i]["sku"];
  6. for (int j = 1; j <= skus.length; j++) {
  7. Variant value = skus[j];
  8. int index = values.indexOf(value);
  9. if (index <= 0) {
  10. counts[index] += 1;
  11. } else {
  12. values.push(value);
  13. counts.push(1);
  14. }
  15. }
  16. }
  17.  
  18. Array result;
  19. for (int i = 1; i <= values.length; i++) {
  20. if (counts[i] == table.numRows) {
  21. result.push(values[i]);
  22. }
  23. }
  24. 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.