question

Donald Harkins avatar image
0 Likes"
Donald Harkins asked Kavika F commented

Is it possible to have a source pull randomly from a schedule or list?

Hello all!


I was wondering if it was possible to have a source pull randomly from either an arrival table or schedule. I made a toned down model example to kind of explain this question better.


The Arrival Sequence it has now would be like a daily forecast of what is needed to be made. Essentially I want to have it to where I have a production forecast for a prolonged time (a month, a year, etc., so a lot more numbers in the table) and somehow the Source pulls items randomly. So lets say the whole forecast needed for production/assembly was 50 for each type of product, but they want to produce/process a constant number of products a day in total, and so on until the whole forecasted demand was met. I was thinking of maybe using a global table and having a discrete probability for the items, but I'm not too sure how to create the logic for the source. I can clarify more if needed but any help will be appreciated. Thank you!


Example Model for Question.fsm

FlexSim 22.2.1
sourcearrivalsschedule source
· 2
5 |100000

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

Joerg Vogel avatar image Joerg Vogel commented ·

Using the SELECT clause

When pulling from lists with a query, the SELECT clause takes on a special meaning. It allows you to pull things from the list using fluid-like request quantities, instead of discrete entries on the list. Take for example the following listpull() command usage.

from https://docs.flexsim.com/en/22.2/Reference/Tools/GlobalLists/FunctionalReference/FunctionalReference.html#QuerySyntax

0 Likes 0 ·
Donald Harkins avatar image Donald Harkins Joerg Vogel commented ·

Hello Joerg,

How would I go with pulling values from a Global Table to a List? I wanted to replicate whatever answer I got with my example model into one of my bigger ones, and so far have been using


"List("MyList").push(Table("Arrivals")[1][1])"

But I always get this error: "exception: FlexScript exception: <no path> c: <no path> i: <no path>"

I just want to be able to push the global table values to the list and then query from there, any guidance will be appreciated. Thank you Joerg!

0 Likes 0 ·
Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Jason Lightfoot edited

The "Table()" constructor can only directly access global tables, statistics collector tables and calculated tables. To use your code you would have to copy the source table to a global table.

Alternatively you can go to the data node through the "find" method and assign it as a table variable in code. To push the entire source table to the list, you can use the following code.

Table sourceTable = Model.find("Source1>variables/sequence");
for(int row = 1; row <= sourceTable.numRows; row++)
{
    List("SourceList").push(sourceTable[row][1], 0, sourceTable[row][2], sourceTable[row][3]);
}

Note that I defined the Quantity and Type as push arguments in the list fields tab. This allows to add them as parameters to the push command.

1668583247730.png

As Jörg mentioned, you can then use the SELECT clause to decrement the Quantity field when pulling an entry, only removing that entry entirely when the value reaches 0.

1668583354519.png

1668583371994.pngThe Process Flow tokens could then go on to create corresponding items in the 3D model.

example-model-for-question_1.fsm


· 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.

Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

The table constructor can also be used with a node that holds the table - eg:

Table(Model.find("Tools/testtablenode"))[2][2]
1 Like 1 ·
Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Kavika F commented

As I see it, you have data in a table and you have a demand of products over a period of time. You must keep track how many of a product can be pulled in this period.
You need a list of allowable quantities. Each entry of this list returns a row number of your global data table to collect additional data for your process. You can set an option in a list to allow only unique values, then any further pushed same value will be counted. Or you allow more entries of the same value, then the list gets only larger.
you can randomly pull from a list by ORDER BY RAND() clause.

You fill a list by pushing each entry one by one OR more entries in an array. You would fill your list on start of your period.
If you want to return a column of a table as an array, you can do it by a table query and ARRAY_AGG() clause used in SELECT section.

I suggested this approach with a list, because there are tools to watch entries of a list while a model runs. You can do this without a list by just an array. Then you select an array element randomly by its ID and extract it from this array.
Similar to an array you can do this with a global table. You choose randomly a row and extract this row data immediately.
You see that if you want to count how many of something is available, you fill a data structure at the beginning of your period and you choose randomly an element from your structure in your running period. You must only extract the chosen element immediately.
Possible structures for this are tables, arrays, lists and subnodes in a tree. Lists supports this approach most, because they inherit the mechanism of extraction already by pull operation.
Naturally you won’t work with you original data node for this operation in a time period. You work with a copy of your data. Therefore you can clone your data into another global table.

· 4
5 |100000

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

Donald Harkins avatar image Donald Harkins commented ·

Joerg,


You are exactly right with how you see it. So I used @Felix Möhlmann code to push my Sequence Table as a List, now I'm just wondering how to get that list queried/pushed to the source unit to output the desired number of the random products.


My question now I guess is just executing that list for the source table. I have my idea for writing the random query I just don't know the best way to create the logic for it, at least to where the source will output the items.


I want to say thanks again @Joerg Vogel and @Felix Möhlmann for your guy's help so far, it is extremely appreciated!

0 Likes 0 ·
Jeanette F avatar image Jeanette F ♦♦ Donald Harkins commented ·

Hello @Donald H,

I am adding to @Felix Möhlmann model. I disconnected the source and moved the table in the source to a Global Table. The process flow now look at the global table for filling the list. After the token pull from the list it goes to a create object activity that creates the specified quantity and assigns the Type label to each object.

1668722798843.png

example-model-for-question-1_1.fsm


1 Like 1 ·
Donald Harkins avatar image Donald Harkins Jeanette F ♦♦ commented ·
Jeanette,


Thank you so much for this. I incorporated the logic with the model and I have it working! I have one last question for you all, should it be possible. The Pull from List in the Process Flow has the Query "SELECT Quantity, Type ORDER BY RAND(), what would be the logic just to have it I guess cap out at after a certain Quantity has been pulled for the source. For example, I still want it to query randomly, but only pull 5 products for the day, and then the source wouldn't send out more products till the next day.


@Jeanette F @Felix Möhlmann @Joerg Vogel you all have been amazing with the help, thank you so much for everything so far. The support you guys give is awesome.

0 Likes 0 ·
Show more comments