You are here

Keeping track of queue events

I am building a model in which there is a queue, and individuals can go onto the queue or come off it. I have a state variable for the queue length with rules to add one or delete one when people join or leave the queue. This works fine except when someone joins and leaves at the same time, then the queue length still decreases! The add rule does not fire. How can I fix this?

Forums: 

A state variable can only update with one rule at a time, and if two are triggered simultaneously (i.e., by events that have a common cause) only one will fire -- and there is no pattern to which one it is. This is because the result of firing two rules simultaneously might depend on the order in which they are fired. However if all you are doing is adding to or subtracting from a value, the order makes no difference. You could use a compartment to represent the queue, with squirts going in and out to represent people joining and leaving. Since squirts are always additive, any number can apply at once.

 

Alternatively, create a single event for 'queue length changed' and derive it from both the add and remove events. If their values are 1 and -1 respectively, and the combined event just uses trigger_magnitude() for its equation, then if they both fire at once, the combined trigger magnitude will be zero so the derived event will not fire.