question

Jacob E2 avatar image
0 Likes"
Jacob E2 asked Jacob E2 commented

Combine Items with Matching String Label?

Hello,

I am trying to combine 2 items with a matching "Order" Label. Also, I do not want any items to enter the combiner until there is a match. I found a question and model that seems to do exactly what I need. So I modified the logic from Matt Long's answer on this question (Similar Question) to match my labels. It worked in my simple example model using random numbers 1-10, but failed when I tried to implement it in my much larger actual model. My actual model has string values instead of integers for the "Order" label value. So I'm assuming that is what is causing it to fail.


Can this logic (or simpler logic) be modified to work with labels that contain strings?


Model:Combiner Match Items by Order.fsm


1652192321459.png


Thanks,
Jacob


FlexSim 22.0.1
combinercombiner itemtype
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 Jacob E2 commented

You have to adjust the pull code to read the label as a string. Currently they are assigned to an integer variable, in which case any string evaluates to 0. So later in the code, the number 0 is compared to the other item's labels, resulting in no match.

Don't forget to also change the reset value of the 'MatchedOrder' label on the combiner. The code below assumes an empty string to be the default value.

/**Matching Orders*/
string MatchedOrder = current.MatchedOrder;
if (MatchedOrder != "") {
    //We previously matched an item so pull the matching order from the other queue
    if (item.Order == MatchedOrder) {
        current.MatchedOrder = "";
        return 1;
    }
    return 0;
}

string Order = item.Order;
//Search the opposite queue for the same order
int otherPort = port % 2 + 1; //Grab the other port rank so we look at the other queue
treenode queue = current.as(Object).inObjects[otherPort];
for (int i = 1; i <= queue.subnodes.length; i++) {
    if (queue.subnodes[i].Order == Order) {
        //Found a matching order, save the order on a label
        current.MatchedOrder = Order;
        //Now pull the item that just entered the original queue
        return 1;
    }
}
//No matches, pull nothing
return 0;
· 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.

Jacob E2 avatar image Jacob E2 commented ·
Thank you, Felix!

Exactly what I needed!

-Jacob

0 Likes 0 ·