Schedule Timeout Block workaround
7 次查看(过去 30 天)
显示 更早的评论
How can I preset a threshold for entities based on attribute (e.g. patience) whilst keeping counts of early departures from a FIFO queue in SimEvents r2019b?
0 个评论
回答(2 个)
Abdolkarim Mohammadi
2020-5-28
AFAIK You cannot implement it by SImEvent's default blocks. What you need is a customized FIFO queue and is only possible using the MATLAB Discrete-Event System (MDES). This block allows you to programmatically define your customized queue.
Your MDES would need two input ports, two storages, and one output. Your customers (which are entities with two attributes of WaitingTime and EntryTime) arrive at the first storage and are stored in storage 1 which has a FIFO layout. Patience update events (entities) arrive at the second input port. They invoke an event to iterate over the existing entities in the storage 1 (using the method obj.eventIterate). You define an event action method for the iteration (say, CustomerIterate) which was invoked inside the obj.eventIterate and assign new values to the attribute WaitingTime. The new WaitingTime is calculated by subtracting the EntryTime from the current simulation time. In order to get the current simulation time, you need to create a simulink function which has a digital clock in it. You must declate this simulink function using the getSimulinkFunctionNamesImpl method.
Dan Hernandez
2021-1-26
Hi, I'm going to give my own take on this one. Bear in mind that this approach is admitedly a hack.
An alternative to Discrete-Event System could be using the Entity Find block to find and extract entities after they have spent a set amount of time in a block. This is a variation of the Find and Extract pattern. See below.
Essentially, you can use the timestamp pattern to record when an entity gets created (the entry event action of an entity generator). A second attribute can be used to define "Patience" (how long an entity is willing to wait in a certain block). Then, we constantly monitor entities and subtract current simulation time from the creation timestamp, if the value is greater than the Patience attribute we extract the entity. See the model below.
In the entity generator we have:
We connect a Resource Acquirer to the Generator and then we add the Entity Server and the terminator.
We add a Resource Pool, the settings as default. Then we add another Entity generator and we call that the Trigger Entity Generator. In here we keep Period to 1, and change entity type to Trigger.
We connect the Trigger Entity Generator to the Entity Find block, and tick the options Extract found entities and Additional filtering condition.
For the additional filter condition, you would write
The last bit then, is to add the timestamp function itself, which can be done with a Simulink Function. Just see the pattern here.
I hope that helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Events 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!