question

Kevin avatar image
0 Likes"
Kevin asked Kevin commented

Conditional Ports

Hello,

I have a simulation with a queue QAll that performs batching to send items 5 at a time to one of 6 other queues Q1-6 which are each connected to a processor P1-6 that uses batch processing to send 5 items to the sink.

1743444007168.png

I want several conditions in here.

1. QAll only sends a batch to queues Q1-6 if their corresponding processor P1-6 is idle.

2. P2 will only start working once the queue content in QAll is above 20, P3 at 30, P4 at 40, P5 at 50 and P6 at 60.

I am trying to solve this with custom code on QAll under Output, Send to Port, Conditional Port. Here is my code I have so far, the simulation runs but receiving Flexscript errors retrieving content on object QAll at MODEL:/QAll>variables/sendtoport

My custom code:

/**Custom Code*/

Object item = param(1);

Object current = ownerobject(c);


// Define the queue length thresholds for each

int threshold1 = 0;

int threshold2 = 20;

int threshold3 = 30;

int threshold4 = 40;

int threshold5 = 50;

int threshold6 = 60;


// Iterate over each processor and its corresponding queue

for (int i = 1; i <= 6; i++) {

Object processor = Model.find("P" + i).as(Object);

Object qAll = Model.find("QAll").as(Object);


// Determine the current threshold

int currentThreshold;

switch (i) {

case 1: currentThreshold = threshold1; break;

case 2: currentThreshold = threshold2; break;

case 3: currentThreshold = threshold3; break;

case 4: currentThreshold = threshold4; break;

case 5: currentThreshold = threshold5; break;

case 6: currentThreshold = threshold6; break;

}


// Check if the processor is idle and the QAll queue length is below the threshold

if (processor.stats.state().value == STATE_IDLE && qAll.stats.content.value >= currentThreshold) {

// Send the item to the corresponding queue

return i; // Return the port number of the Q1-6 queues

}

}


// If no processors are idle or all queues are full, decide on a default action

return 0;

1743444580162.png

Any help troubleshooting this is appreciated!

FlexSim 23.2.0
conditional port
1743444007168.png (85.3 KiB)
1743444580162.png (54.2 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.

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Kevin commented

The Send to Port field is not suitable for this. It is evaluated once per item and thus can't react to changing conditions.

I would use a small Process that batches the items, pulls a processor from a list based on the activation requirement and then releases the items to it. When the queue content passes one of the thresholds the list backorders can be reevaluated to check if another processor is now allowed to be pulled.

list-pull-with-backlog-condition.fsm


· 4
5 |100000

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

Kevin avatar image Kevin commented ·

I tried to copy the same logic into my model and now I get this error: time: 10.869352 exception: FlexScript exception: Label property ActivationLimit retrieved on /P1. Label does not exist. at MODEL:/Tools/GlobalLists/Processors>variables/fields/AboveLimit/expression

I get the same error for every processor and the items just keep piling up in the queue. Also where can I adjust the limits now, in case I want to change the thresholds to 10 for p2 and other values for p3-p6? Thank you for your help

0 Likes 0 ·
Kevin avatar image Kevin commented ·

The batching process seems to work, but the processors don't pull from the list 1743509527305.png

0 Likes 0 ·
1743509527305.png (27.7 KiB)
Felix Möhlmann avatar image Felix Möhlmann Kevin commented ·

The answer to both your questions is that each processor has a label called "ActivationLimit". The "AboveLimit" list field reads this value and compares it to the number of items in the queue to determine whether the processor can be pulled or not.

1743511479843.png

If you change the limits, remember to also adjust the code in the Custom Code activity that reevaluates the backorders. It currently only does so if the queue content reaches (N*10 + 1) since the limits are all multiples of 10.

0 Likes 0 ·
1743511479843.png (3.8 KiB)
Kevin avatar image Kevin commented ·
Thank you this solved it for me!
0 Likes 0 ·