Update Target Quantity

Update Target Quantity

michela_08
Not applicable
89 Views
12 Replies
Message 1 of 13

Update Target Quantity

michela_08
Not applicable

[ FlexSim 22.2.3 ]

In my model, I am using 5 combiners and 5 Queues. I am using the Join mode. In the combiner tab of each combiner, I want to update target quantity of each combiner using global table which is imported from excel sheet. There is an option in "combiner" tab where I am able to update the target quantity based on that specific combiner.

But in my case I want to update combiner target quantity for all the respective combiners using global table for that specific combiner's name from a single global table.

How to achieve this?

target_quantity_update.fsm

0 Likes
Accepted solutions (1)
90 Views
12 Replies
Replies (12)
Message 2 of 13

Jacob_White
Community Manager
Community Manager
Accepted solution

Hi @michela_08,

In my attached model I have set up an "on reset" trigger on combiner 5. This trigger runs the following code block

treenode thelist = getvarnode(current,"componentlist");
treenode thesum = getvarnode(current,"targetcomponentsum");
setnodenum(thesum,Table("Combiner_Quantity")[current.name][1]);  
setnodenum(cellrowcolumn(thelist,1,1),Table("Combiner_Quantity")[current.name][1]);

This code finds the nodes for the combiners' target quantity, and then sets the value in the nodes to be whatever value that combiner should have according to the table value.

The following link also explains more about this code.

https://answers.flexsim.com/questions/70097/update-combiner-target-quantity-by-code-when-the-l.html

target-quantity-update_JW.fsm

0 Likes
Message 3 of 13

michela_08
Not applicable
Thank you @Jacob W2, I have few doubts regarding the model.

In the model, the "Combiner 2" 's target quantity is not changing and is 0 even after running the model. For all other combiner's its updating.

What does the code in the script represent? is it only for specific combiner's? Can you please tell me what the code in the script is useful for target quantity?

0 Likes
Message 4 of 13

moehlmann_fe
Observer
Observer

None of the combiners in the attached model seem to actually have the reset code set. So none of the should be updating when you change the table values.

A combiner has two nodes in its attribute tree that govern how many items are received through each port (starting at rank 2, port 1 always only receives the container item) before the process starts.

Those are the "componentlist" and the "targetcomponentsum" (marked yellow in the screenshot below).

1669808798498.png

The componentlist represents the list you see in the combiner's properties. The value is stored in the "Target Quantity" node (pink)

1669808828026.png

As such it posesses a subnode structure that can be accessed as a table. The level below the main node represents the rows ("From Input Port 2") and the subnodes of those are the respective cell values (Target Quantity, Current Quantity (not shown in the properties)).

The "targetcomponentsum" is the total sum of items received through all ports. Since there is only one port (port 2) that will receive items, the value of the this node and the "Target Quantity" in the component list are the same.

The code first gets references to the these two nodes. It then assigns the value from the global table to "targetcomponentsum" and "Target Quantity", depending on the name of the object that is executing the code (the combiner).

The code to assign the values comes from older versions of FlexSim. The same can be done with the following using the newer dot-syntax.

// Read the target quantity from the global table
int qty = Table("Combiner_Quantity")[current.name][1];
// Get reference to the "componentlist" node as a table class variable
Table thelist = getvarnode(current,"componentlist");
// Get reference to the "targetcomponentsum" node
treenode thesum = getvarnode(current,"targetcomponentsum");
// Set the "Target Quantity" through port 2 (first row, first column) to be equal to the table value
thelist[1][1] = qty;
// Set the value of "targetcomponentsum" to be equal to the table value
thesum.value = qty;
0 Likes
Message 5 of 13

michela_08
Not applicable
Hi @Felix Möhlmann

A model with the code you stated would be really helpful. It is being difficult for me to understand where to add the code so as to achieve the combiner target quantity.

Can you please attach a sample model so as to understand clearly?

0 Likes
Message 6 of 13

moehlmann_fe
Observer
Observer

As Jacob suggested in his answer, a good place to put the code, if it only has to run once ahead of each simulation run, is the "On Reset" trigger of the combiners.

See Combiner1 in the attached model. I also modified the global table to use the combiner names as row headers, so it is easier to access the correct row from the trigger.

target-quantity-update_1.fsm

0 Likes
Message 7 of 13

michela_08
Not applicable
Thank you @Felix Möhlmann , model is really helpful.

I have one more doubt, If i had to set combiner target quantity by matching a label?

For example, the boxes entering the Queue will have Item_type label as "L" and "H". Suppose the combiner target quantity for "L" is 5 and for "H" is 2. I want the combiner target quantity to be updated based on this item_type label and take the items from the queue based on the item_type label.

For item_type = L : Target quantity should be 5

For item_type = H : Target quantity should be 2

How to do this for the same model?

0 Likes
Message 8 of 13

moehlmann_fe
Observer
Observer

You use the "On Entry" trigger instead. You can actually find the pre-defined option "Update Combiner Component List With Labels" for that trigger, which Jabob's and my code are based on.

1670488021290.png

The difference is that the code first checks if the item entered through port 1 (so it is the container/main item).

It then sets the component quantity depending on a global table, where each column represents a label value and the rows represent the quantity received through the other ports (rank 2+).

Since the combiners in your model only have two ports, that code can be simplified to what you see below and the rows of the global table can instead be used to refer to the different combiners.

if(port == 1)
{
    //Determine column based on label
    int column = 1;
    if(item.Type == "H")
    {
        column = 2;
    }

    // Read the target quantity from the global table
    int qty = Table("Combiner_Quantity")[current.name][column];
    // Get reference to the "componentlist" node as a table class variable
    Table thelist = getvarnode(current,"componentlist");
    // Get reference to the "targetcomponentsum" node
    treenode thesum = getvarnode(current,"targetcomponentsum");
    // Set the "Target Quantity" through port 2 (first row, first column) to be equal to the table value
    thelist[1][1] = qty;
    // Set the value of "targetcomponentsum" to be equal to the table value    
    thesum.value = qty;
}

target-quantity-update-2.fsm

0 Likes
Message 9 of 13

michela_08
Not applicable
Hi @Felix Möhlmann

Thank you for the model and explanation. I have one more scenario

For one combiner there are 3 input ports.

Input port 1 : source

Input port 2 : target qty = 2( fixed)

Input port 3 : based on the code you have provided above.

Note : items coming from port 2 will have Item_type label = L or H.

For example, the target qty and targetcomponent sum will be different here. If target qty from port 3 will be 9. Then targetcomponentsum = 12 [ port 1 (1 qty), port 2 (2 qty) , port 3( 9 qty) ]

How to do this?

0 Likes
Message 10 of 13

moehlmann_fe
Observer
Observer

Updating the component list when the first item enters through port 2 should work, though you should close the output of the object connected to port 3 until the target was updated.

combinerTargetPort2.fsm

Note that the container item is not part of the targetcomponentsum.

0 Likes
Message 11 of 13

Jeanette_Fullmer
Community Manager
Community Manager

Hi @michela-08, was Jacob W2's answer helpful? If so, please click the "Accept" button at the bottom of 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
Message 12 of 13

joerg_vogel_HsH
Mentor
Mentor

There is a standard procedure to update components lists in combiners. It is a template, which copies columns of a global table to nodes in the tree of a combiner to replace a component list, which you can also edit manually from properties panels.

You can adjust this code to update the involved tree nodes like it is suggested at many places here at this forum by label values -

OR you can update the global table cell values in an assign structure and let handle updating a component list by the standard procedure.

If you want to get the standard procedure work successfully you only have to update the involved global table cell values before an item is entering a combiner through input port number one.

0 Likes
Message 13 of 13

michela_08
Not applicable
Thank you @Felix Möhlmann
0 Likes