question

Jyhjeng D2 avatar image
0 Likes"
Jyhjeng D2 asked Jyhjeng D2 commented

Can we use timer in 3D model?

Hi:


I have a question on how to set a condition to put the customer into one of two alternative positions. One alternative is to arrange for the customer to go to the service desk, and the other is to the unhappy customer link. According to Tutorial TASK 1.1 - BUILD A 3D MODEL (https://docs.flexsim.com/en/20.2/Tutorials/FlexSimBasics/1-1Build3DModel/1-1Build3DModel.html ) and TASK 1.2 - GET DATA FROM THE 3D MODEL (https://docs.flexsim.com/en/20.2/Tutorials/FlexSimBasics/1-2GetData/1-2GetData.html), we can simulate the two alternatives by using a global list. Is it possible to add a timer in the 3D model to keep track of the waiting time in the waiting line and ensure the customers will go to the unhappy customer link if the waiting time is more than 200 s? Without using the global list, as suggested in the tutorial, we tackle the same problem by using the timer in the 3D model. Note that I am not talking about the timer in the process flow model, which has already been solved. I am talking about using the timer in the 3D model. The Flexsim 3D model can be downloaded at

https://drive.google.com/drive/folders/1Av_A8muhtfujOcILEtnX8TqIM03OfORg?usp=share_link

FlexSim 22.0.1
use timer in 3d model
5 |100000

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

1 Answer

·
Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Jyhjeng D2 commented

There are currently two ways to realize a timer in the 3d model. The first is to use message. They can be send with a delay time. The logic would thus be split up into two parts. The first is scheduling a message to be send and the second, in an On Message, trigger would activate once that message is received and do actions depending on the situation at that time.

A message can include up to three variables that are passed into the On Message trigger. However, for delayed messages, those can only be numerical values, so you have to come up with a way to refer to the object the message relates to by a number.

In the attached model I use an array label with 100 entries that the items get assigned to cyclically (based on the input statistic of the queue). If there are never more than 100 items in the queue, then this matches each item with a number it can later be refered by.

In the On Entry trigger, the item is written to the array and the message is scheduled. In the On Exit trigger the item reference is removed from the array. If, when the message is received, the reference in the array is still valid, the item must still be in the queue and is then released through the second output port.

I also added a visual indicator of when items will leave the queue that is drawn in the queue's On Draw trigger.

3d-Timer.fsm

In version 22.1, the "await" statement was added which allows to suspend the execution of code for either a set time (delay) or until a certain event happens.

This could be used to build a similar logic to that above with the benefit that everything can happen in a single trigger, which would make the need for the array to have a reference to the item unnecessary.

https://docs.flexsim.com/en/22.1/Reference/CodingInFlexSim/WritingLogic/WritingLogic.html#coroutines


3d-timer.fsm (29.4 KiB)
· 6
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 ·
I prefer the use of a delayednodefunction() to the message as I can better see the intent in the event list by which node is being called - just a thought.
0 Likes 0 ·
Jyhjeng D2 avatar image Jyhjeng D2 commented ·

Dear Felix:

Thank you for your reply. Two things is not clear to me. First, how to add on the items such as On Entry, On Exit, etc. of Trigger of queue 1. For example, in the On Entry, it shows: Add to array, add label and send message. How do I do that?

Second, how do I add a visual indicator of queue 1?

For my two questions, is there any video tutorial I can learn about them?

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Jyhjeng D2 commented ·

I directly edited the code of the triggers in the code editor window. 1669803533979.pngThe text written in the first line, between "/**" and "*/" is what will be displayed as the trigger description.

1669803592158.png

If needed you can learn about the basics of coding in FlexSim, you can start here.

The visual indicator uses the command drawrectangle to draw the colored lines next to the queue. The code is placed in the "On Draw" trigger of the queue, so the bars are updated every time the screen refreshes.

The code loops through all items that are currently in the queue in a for-loop. It checks the time until their maximum wait time has elapsed. Based on that value a color is chosen from the custom color palette "RedGreenGrad(ient)" that was added in the toolbox. Then a bar of that color is drawn, with its length scaled to represent the amount of time left.

// Draw to scale of model (so bar size is independent of the size of the queue)
// And disable lighting, so the bars are always brightly visible
drawtomodelscale(current);
fglDisable(GL_LIGHTING);

// Loop through items
for(int i = 1; i <= current.subnodes.length; i++)
{
    // Assign current item to variable and read entry time label
    Object item = current.subnodes[i];
    double entryTime = item.EntryTime;
   
    // Choose color from color palette, depending on time left
    Color barColor = Color.fromPalette(entryTime + 200 - Model.time, "RedGreenGrad");
   
    // Draw bar with length scaled to time left and position depending on the item rank "i"
    drawrectangle(0, -current.size.y - 0.2 - 0.12*i, 0.02, (entryTime + 200 - Model.time)/100, 0.1, 0, 0, 0, barColor.r*255, barColor.g*255, barColor.b*255);    
}

// Enable lighting again
fglEnable(GL_LIGHTING);
0 Likes 0 ·
1669803533979.png (2.1 KiB)
1669803592158.png (16.5 KiB)
Jyhjeng D2 avatar image Jyhjeng D2 commented ·

Dear Felix:

I follow your code in Triggers of Queue 1, but I still need help getting the result as yours. Please check what is wrong with the codes.

Also, in the output, the send to port is set to 1 in your program. However, when I set it to 1, it creates an error. Finally, my file can be downloaded at the following link. Note I still need to try the visual indicator.

https://drive.google.com/drive/folders/1Av_A8muhtfujOcILEtnX8TqIM03OfORg?usp=share_link

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Jyhjeng D2 commented ·
You are getting an error when you set "Send to Port" to 1, because the color palette that is used to draw the visual indicator in the "On Draw" trigger is missing from the model.

You need to set "Send to Port" to 1 though. With "First available", items that can't go to the processor will immediately go to the sink instead of waiting.

That is why the queue is set to send all items to the processor. Only the "releaseitem" command in the "On Message" trigger overwrites this and sends the items through the second output port when the wait time elapses.

0 Likes 0 ·
Jyhjeng D2 avatar image Jyhjeng D2 Felix Möhlmann commented ·
Dear Felix:


Thank you for your explanation. Your method works.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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