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.
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;
Any help troubleshooting this is appreciated!