How to create a label in Flexsim using By Percentage

How to create a label in Flexsim using By Percentage

Aleksey_KovalenkoLMTB6
Contributor Contributor
11 Views
13 Replies
Message 1 of 14

How to create a label in Flexsim using By Percentage

Aleksey_KovalenkoLMTB6
Contributor
Contributor

[ FlexSim 24.2.1 ]

How to create a label in Flexsim using By Percentage but the total number of one label of two is not more than 100pcs. Thank you in advance for your help.

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

moehlmann_fe
Observer
Observer
Accepted solution

You'll have to write some custom code for this. I would generate one value as normal, then generate another value until the sum of both doesn't exceed 100. One value is assigned to the current item, the other one is stored in a label on the source, so it can be assigned to the next item. If no stored value exists, a new value pair is generated.

In the example model I use an empirical distribution to generate the random values, so the code is less cluttered and hopefully easier to understand.

custom-percentage-label.fsm

/**Custom Code*/
Object current = ownerobject(c);
Object item = param(1);
int rownumber = param(2); //row number of the schedule/sequence table

// Make sure that source labels exist
current.labels.assert("StoredValues", []).value;
current.labels.assert("Index", 0).value;

if(current.StoredValues.length == 0)
{
    // No more stored values -> Create new ones and increment index
    double firstValue = Empirical("TestDistribution").get(getstream(current));
    double secondValue = Empirical("TestDistribution").get(getstream(current));
    while(firstValue + secondValue > 100)
    {
        // Keep rerolling until sum is not larger than 100
        secondValue = Empirical("TestDistribution").get(getstream(current));
    }
    // Update source labels
    current.StoredValues = [firstValue, secondValue];
    current.Index += 1;
}

// Assign labels to item
item.Value = current.StoredValues.shift();
item.PairID = current.Index;
item.color = Color.byNumber(item.PairID);
0 Likes
Message 3 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Dear Felix,

thank you for your ideas in supporting me in my issue.

I think I did not put the question correctly.

Below is an example of a problem on the screen that needs to be solved.

Please take a look at it if you have a chance to help, I would be grateful.


Thank you in advance!

1728372022715.png

0 Likes
Message 4 of 14

moehlmann_fe
Observer
Observer

Sorry, but I don't see what the problem in your screenshot is. You have the pass/fail number, can thus calculate the failure rate and use it in the format you show.

It is possible to assign the label in a single expression using bernoulli(). Though that can only return numbers, not strings.

0 Likes
Message 5 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Felix, the problem is as follows:

When randomly generating repair items, when creating an item using the By Percentage function, 1658,0 items (51,95%) are generated. These items go to the Queue after creation. After reaching Queue I need to create a batch of 6 items to be sent to the next workcenter.

When 1658 repair items are generated, the number of batches is not an even number 1658/6 = 276,3 and I still have items on Queue that cannot be formed into a batch.

So the goal is to randomly generate a number of repair items close to 51,95% but still even number of items in the batch. For example 1656 pieces. In this case the number of batches will be 1656/6 = 276, and it will give the opportunity to form batches of all items and pass to the next work center.


Can we use another solution instead of the By Percentage function?



1728377848072.png


0 Likes
Message 6 of 14

moehlmann_fe
Observer
Observer

There are multiple ways to do this, but they will all give an 'imperfect' result because, well, you can't have a random distribution if the quantity of each value is predetermined.

1) You assign values by percentage as normal, but each value only has a limited contingent. Once that has run out, the value is simply not allowed anymore and the rest of the items will get assigned the other value. This will typically lead to a large chain of same type items at the end of the created batch.

2) You first create an array of all possible values that will be assigned and then pick and remove a random value from that array for each item. Here you will end up with slightly fewer long chains of same type items than would be expected. Each time a value is picked it is removed from the array and thus less likely to be picked again for the next item. This effect will become more pronounced toward the end of the batch of created items.

predetermined-qtys-randomly-distributed.fsm

The detrimental effect of solution 2 is smaller and usually what I would go for if needed.

However, my preferred solution would be to adjust the model so it will continue to work with partial batches. For example by adding a maximum wait time.

0 Likes
Message 7 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Dear Felix,

thank you for your help!

I will use your ideas!!!


Regards,

Oleksii

0 Likes
Message 8 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor


Felix, I'm sorry to disturb you.

How can I modify my model according to your two suggestions if I create a product in process flow.


Thank you in Model_rejection_rate.fsmadvance for your help!

Oleksii

0 Likes
Message 9 of 14

moehlmann_fe
Observer
Observer

Use the code from the reset trigger (adjusted for the new environment, main replacing "current" with "token" to create the array of possible values on the token.

Then pick values from it like in the creation trigger when assigning the label in the Create Objects activity. (Since the child tokens can read labels on the parent, you can treat the array as being on the label on the child token).

1728403898081.png

0 Likes
Message 10 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Dear Felix!

I tried to modify the code you suggested.

I inserted it in the places indicated on the screenshot.

But I got an error and the required result is on the halfpenny.


If you have an opportunity, you can check what I did wrong.


Thank you in advance!

Oleksii


1728452229238.png


0 Likes
Message 11 of 14

moehlmann_fe
Observer
Observer

You need to keep the header intact, otherwise "token" and other variables are not defined. Only copy the 'functional' part of the code.

1728455263374.png

model-rejection-rate_1.fsm

0 Likes
Message 12 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Dear Felix!

Now it makes more sense.

But unfortunately only the ‘Good’ value is generated, the ‘Bad’ value is not generated from the array.

Sorry to disturb you, but this question is very important for me.

Please check it.

Thank you in advance!


Olekii

0 Likes
Message 13 of 14

moehlmann_fe
Observer
Observer

Huh, somehow the code that generates the value array was not toggled as FlexScript. The version below should work.

model-rejection-rate_2.fsm

0 Likes
Message 14 of 14

Aleksey_KovalenkoLMTB6
Contributor
Contributor

Dear Felix!

Thank you for your time and support!!!


Everything works!!!


Oleksii

0 Likes