question

Mark avatar image
0 Likes"
Mark asked Jason Lightfoot edited

Decide

Hi, can a "decide" in process flow function like the setup option of the processor "if item label value change" instead of time value, I would like to send the first item in connector 1 and for the second item with the same value will be send to connector 2 going to the sink and so on until a different item label value first item show up..


1691567277783.png


1691567351366.png


How should the script be written?

Thank you answering.


FlexSim 20.2.3
decide activity process flow
1691567277783.png (10.4 KiB)
1691567351366.png (14.6 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 Jason Lightfoot edited

The following code will do that:

// Assert a node in the activity's tree to store the last type in
treenode lastType = activity.find(">variables").subnodes.assert("lastTypeValue", 0); // Compare to the current token's type (or if first token to enter) if(token.Type != lastType.value || getstat(activity, "Input", STAT_CURRENT, processFlow) == 1) {     // Send to 1 if different or first token and update node value     lastType.value = token.Type;     return 1; } // Send to 2 otherwise return 2;
· 2
5 |100000

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

Mark avatar image Mark commented ·

Thank you for the quick answer, the code works well.

1691573352499.png

0 Likes 0 ·
1691573352499.png (65.6 KiB)
Jason Lightfoot avatar image Jason Lightfoot ♦♦ commented ·

Note that this won't work as-is for an Object Process Flow with multiple instances. For that you can use the following code which will also work for a General Process Flow:

// Assert a node in the activity's tree to store the last type in
Map lastTypes;
treenode typesNode = activity.find(">variables").subnodes.assert("lastTypeMap", lastTypes);
lastTypes=typesNode.value;
int lastType=lastTypes[current];
lastTypes[current]=token.Type;
typesNode.value=lastTypes.clone();
// Compare to the current token's type (or if first token to enter)
if(token.Type != lastType || getstat(activity, "Input", STAT_CURRENT, current) == 1)
{
                    
// Send to 1 if different or first token and update node value
return 1;
}
// Send to 2 otherwise
return 2;
0 Likes 0 ·