question

YANG W2 avatar image
0 Likes"
YANG W2 asked Joerg Vogel commented

Dispatcher settings

I wonder if there are shortest distance if available, how about random port if available?
Because random doesn't have this option, is that mean random port will consider the Task Executor are not available and Task executor will only do the task after available?

FlexSim 20.2.3
flexsim 20.2.3disptacher setting
· 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.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Hi @YANG W2, was tannerp's answer helpful? If so, please click the red "Accept" button on their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

tannerp avatar image
1 Like"
tannerp answered Joerg Vogel commented

Hi @YANG W2,

To help answer your question, I think it is important to understand that the "if available" portion of picklist option just adds one piece of logic to the regular logic. That added piece is a check to see if the input port of the object is open using some variation of the following code:

if (ipopen(current.outObjects[Port])) {
    return Port
}

For example, the code for "Shortest Distance" and "Shortest Distance If Available" are shown below and you can see that there is only a slight difference between them.

Using that same logic, you can add a similar check to the "Random Port" logic to make it "Random Port If Available". The "Random Port" logic is quite simple and just uses a duniform function. You can add logic to check if the input port returned by the duniform function is open and then you'll have "Random Port If Available" logic.

Initial logic:

"If Available" version:

Hope this helps!


1603749125275.png (148.9 KiB)
1603750046939.png (25.6 KiB)
1603750080798.png (14.9 KiB)
· 3
5 |100000

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

YANG W2 avatar image YANG W2 commented ·

Thanks for the reply. But since I am not understand the code, how is it looks like if I want the same logic as how shortest distance if available look like random port is available?

0 Likes 0 ·
tannerp avatar image tannerp YANG W2 commented ·

If you want to assign "Random Port If Available", I suggest you use the duniform function to assign a random port, then you check to see if that port is available. If so, send it to that port. If the random port is unavailable, you need to define what port should be assigned. You can put that logic in the "else" statement as shown in the picture below. In my example, I used port 1 if the "random" port was unavailable.

I'm attaching an example model. You can find the logic in the Dispatcher.

random port if available.fsm

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel YANG W2 commented ·

You can evaluate all output ports of the dispatcher as an array. Then you check each output port if the operator is available. Only available output port numbers stay in the array, any other are deleted from the array. Then you choose by a duniform an index of the array from the first element to the last, which is also the index you get by the length property of the array.

0 Likes 0 ·