question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Ankur A3 commented

Best Way To Feed Data Using Global Table?

Hi Team,

There are 10 products running in plant. Every product runs on its machine. There are 2 types of sub products available for each product. Here is the table for 1 product:

1665035064427.png


These tables have recorded time samples for each type of product for product 1. Now I want to assign this data to product type 1 randomly for each of the subcategory.

I am able to feed this data in model using 2 global tables (1 for type A and other for type B). I this way, there will be 20 global tables for 10 products.

Is there any way to feed this data using 1 global table and assign it randomly based on subcategory?

Thank you!

FlexSim 21.1.5
global tabledatafeeding
1665035064427.png (40.7 KiB)
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

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Ankur A3 commented

You can combine all of the tables into one by adding extra columns that denote the type and sub category.

1665038159917.png

You can then use a query to select a random row of the given type and sub category and read the required value.

// This returns a random load time for type 1B
return Table.query("SELECT Load FROM GlobalTable1 WHERE Type == 1 AND SubType == 'B' ORDER BY RAND() LIMIT 1")[1][1];

Depending on how often you query the table it might make sense to set it as a bundle. This then allows you to index the type columns for faster lookup.

1665038271706.png

1665038294924.png


1665038159917.png (28.8 KiB)
1665038271706.png (6.9 KiB)
1665038294924.png (18.8 KiB)
· 7
5 |100000

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

Ankur A3 avatar image Ankur A3 commented ·

Hi @Felix Möhlmann,

Thanks for your answer!

But what I understood from your answer is it will pick any random value from "Load" column.

Similarly, it will pick any of the random value from "Process" and "Unload" column which may not be from same row.

My agenda is to pick random value with same row number. For eg:

If first value "Load" is picked from row 20 then the value for "Process" and "Unload" should be from same row 20.

1, 26, 9

1665043312240.png

How to make sure, it will work in same way?

Thank you!

0 Likes 0 ·
1665043312240.png (9.1 KiB)
Felix Möhlmann avatar image Felix Möhlmann Ankur A3 commented ·

The query works the way you describe. It chooses a random row. Which values from that row are copied to the result table depends on what you put after the "SELECT" statement ("*" means everything). You can also first assign the result to a table variable and then read the individual values from that.

                     
  1. // Choose a random row from 1B
  2. Table result = Table.query("SELECT * FROM GlobalTable1 WHERE Type == 1 AND SubType == 'B' ORDER BY RAND() LIMIT 1");
  3. double loadTime = result[1][2];
  4. double processTime = result[1][3];
  5. double unloadTime = result[1][4];


0 Likes 0 ·
Ankur A3 avatar image Ankur A3 Felix Möhlmann commented ·
Hi @Felix Möhlmann,

Got it. That's what I was looking for.

One more question if I can ask.

I have to access these values on 3 places. So, in this case how to take these values forward since there values are stored in local variables.

Do I need to use global variables to store these values?

Thanks!

0 Likes 0 ·
Show more comments

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.