Creating a variable in the sink to count items

Creating a variable in the sink to count items

uurrutiaGXB2Q
Participant Participant
110 Views
12 Replies
Message 1 of 13

Creating a variable in the sink to count items

uurrutiaGXB2Q
Participant
Participant

[ FlexSim 23.2.3 ]

I want to know how could I create a varible in the sink triggers (On Entry) that is based on a Table. The value, I want it to be a code.

0 Likes
Accepted solutions (1)
111 Views
12 Replies
Replies (12)
Message 2 of 13

moehlmann_fe
Observer
Observer
Accepted solution

If you assign flexscript to a table cell that is does not need any external paramters then you can use the standard syntax "Table(tableName)[row][col]".

To pass in parameters, access the node of the cell and use "evaluate()" on it. ("Table(tableName).cell(row, col).evaluate(params)")

flexscript-table-example.fsm

0 Likes
Message 3 of 13

uurrutiaGXB2Q
Participant
Participant
The thing is I want to create a varible as a trigger "on entry" of a sink to count items with the following code:

gettablecell(label(current,"ItemCounts"),item.Type,1)

For this reason, I need to specify the varible "As.Table"

The questions would be:

· Where in the triggers could I create the variable?

· How could I speccify to the trigger that is a table?

· Where could I add the code mentioned previosly in the trigger?

0 Likes
Message 4 of 13

moehlmann_fe
Observer
Observer

You don't need to create a table variable for that command. Either the label node has the correct structure for a table and the command works or it doesn't.

The non-deprecated expression would be "current.labels["ItemCounts"].as(Table).cell(item.Type, 1)". In this case the as.(Table) is needed for the compiler to recognize cell() as a valid method.

label-table-example.fsm

0 Likes
Message 5 of 13

uurrutiaGXB2Q
Participant
Participant
Hello again,


Sorry but I can't oper the files. Actually, I have the FlexSim 23.0.14 version...

I don't know if you could help me in another way.

Thanks!

Regards,

0 Likes
Message 6 of 13

moehlmann_fe
Observer
Observer

Here's the same model in version 23.0

label-table-example-23-0.fsm

0 Likes
Message 7 of 13

uurrutiaGXB2Q
Participant
Participant

Hello @Felix Möhlmann

My idea was to use this for pulling the items to the sink from a rack taking into account:

· The time

· The item type (label)

· The quantity

So I created in the source items assigned to a label and the orders in a global table

Then in the hour stablished I want to move the items to the sink respecting the time, quantities and labels.

I can attach you to see my example

Pull_Strategy_Unax.fsm

0 Likes
Message 8 of 13

moehlmann_fe
Observer
Observer

Updating the quantity should happen in the Pull Requirement code before returning the 1. That way it also works if the items don't move to the sink instantly but are transported there in some way.

You could simplify the check slightly by writing the hourly demand to the sink table at the start of an hour. Then you decrement the value by 1 and check if it reached 0. This also has the added benefit that you can keep leftover demand active when a new hour starts.

pull-strategy-unax_1.fsm

0 Likes
Message 9 of 13

uurrutiaGXB2Q
Participant
Participant
Thank you very much @Felix Möhlmann !!
0 Likes
Message 10 of 13

uurrutiaGXB2Q
Participant
Participant

1744702083064.png

Hello!

I have applied your idea in my general simulation and the following error is happening.

I have a problem in pulling the items to the sink. The error that appears is the one that you see in the previous image.

The thing is I want to take out the number of items I have in the table "Demand_CDS" and I can't achieve it, I don't know wihy it happens.

My idea is to be each row one day in the Demand_CDS and then match it with client codes (804,403 (the colums in the table))

I can attach the model in case you can help me

Thanks another time

EIKA_Osoa.fsm

0 Likes
Message 11 of 13

moehlmann_fe
Observer
Observer

- The table name in the Reset trigger of the sink needs to be updated. The row headers of the itemCount label table should also be set to the column headers of the demand table here. We will see why later.

capture1.png

- The user event in your model now only happens once per day. The check that resets the global variable to 1 when it reaches 24 should thus either be changed to change it back once the day gets larger than the number of rows in the demand table or it should stop the model at that point.

capture2.png

- The type values in my example are numbers from 1 to 4. They can thus be matched with the columns from 1 to 4. Your type numbers are 'arbitrary' numbers. Using the type to read from the correct column can thus only work if the type is treated as a string (so it can be equal to the column name).

capture3.png

With these changes you now only need to make sure that the values that get assigned to the items as type are all present in the demand table (which they currently aren't).

eika-osoa_1.fsm

0 Likes
Message 12 of 13

uurrutiaGXB2Q
Participant
Participant

Hello @Felix Möhlmann

Thank you vey much for your detailed answer. It has been very useful.

I have some questions related to this:

  • Could it be posible to repeat the demad table from the start once it is finished and continue with the time?
  • What information gives me in a practical way the itemcounts varible table?
  • Could it be possible to define an hour in each day to start pulling the items to the sink?

Thanks a lot!

Best regards,

0 Likes
Message 13 of 13

moehlmann_fe
Observer
Observer
- As I said, instead of stopping the model you could reset the "CurrentDay" variable back to 1 if it becomes larger than the number of rows in the demand table.

- The "itemcounts" label table defines how many items of each type should still be pulled.

- The items will be pulled as soon as the user event is executed. By changing when the event triggers, you can change when the pull starts. If you want to use a non-regular interval (the pull time changes depending on the day), it would probably be easier to place the code in a Custom Code activity in Process Flow instead and generate tokens to execute the code at specific times in a schedule source.

0 Likes