question

Aditya Prakash avatar image
0 Likes"
Aditya Prakash asked Jeff Nordgren answered

Order of events in Flexsim when Message trigger is used.

Hi, I'm trying to build a model where an upstream queue (Q3) receives multiple items of multiple consignment IDs. Downstream queues(Q4,Q5) when empty, receive all items of one particular consignment form Q3. As soon as a complete consignment enters Q5, Q5 closes input. Q5 opens input again when it's empty. It works perfectly, (though I appreciate if someone can suggest me a better way.) Problem is with a label (input flag) which I'm setting 0->1 in senddelaymessage(Q5,0,Q5) for the last item of consignment exiting Q5, and changing 1->0 in OnEntry of last item of consignment entering, it is not getting updated. My own logs portray that OnEntry is executed before OnMsg, hence the problem. But Flexsim Event logs depict events in true order. What am I missing?

- using itemtype as an consignment ID for simplicity

- Items have a label for total_quantity in that consingment.

- Items are created consignment wise, so no issue of ranking.

- FRSTATE is changed as per consignment in Q3.

- Input port is closed/opened in OnMsg(Exit)/OnEntry

FlexSim 16.0.1
input portoutput portorder of execution
snapshot-2.png (23.8 KiB)
snapshot-3.png (93.8 KiB)
snapshot.png (221.9 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.

Brandon Peterson avatar image
6 Likes"
Brandon Peterson answered Aditya Prakash commented

Aditya,

The reason that events look out of sequence to you is because of how you wrote your code. Basically, your print statements are after the openinput() command in your message trigger. If you were to place them in front of the openinput() command you would see what you expect. You are also setting the label "input_flag" after the openinput() command.

Why does it matter where the openinput() command is? When that command executes it immediately opens the input ports and any events, functions, etc. that occur without creating a new event (zero time or not) will execute before the next command in the function that called openinput().

Ultimately, the short answer is that you need to make sure that openinput(), sendmessage(), etc. type commands are called after you set labels, print outputs, etc. that need to be done before anything else in the model happens.

In regards to a possibly more simple approach I created a model with an alternative method for handling your situation. I used a method where I return a '-1' in the send to port trigger for items that I don't want to release yet. Basically each item checks to see if it is the last item in the group to arrive. If not then it sets a label called "Filled" to '0' and returns a '-1' in the send to port trigger so that it waits. If it is the last then it sets the filled labels to '1' and releases the other items from the queue (The "Filled" label is used as a flag in the queue send to port trigger).

I left your original objects on the top and placed my new ones on the bottom so that you could compare them.

Good Luck,

Brandon


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

Aditya Prakash avatar image Aditya Prakash commented ·

Ok, I was of the view that Flexscript code has compiling approach instead of interpreting. Turns out it is other way around. Thanks @Brandon Peterson

0 Likes 0 ·
Jeff Nordgren avatar image
1 Like"
Jeff Nordgren answered

Aditya, @Aditya Prakash

Attached is your model with a Process Flow solution to consider.

It uses both consolidation queues instead of just one. It uses a global table (SourceTable) to specify the Consignment ID, the quantity to create and the Consignment Qty. The Source (Incoming Flowitems) in the Process Flow just basically determines at what clock time flowitems should be created. It looks in the Global Table for specifics.

Using Process Flow, you don't have to mess with any code to accomplish what you are trying to do. Take a look at the attached model testing-hold-release-2-jn2.fsm and see if it will do what you are trying to make it do.

If you have any questions, please let me know.


5 |100000

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