question

Milosz S2 avatar image
0 Likes"
Milosz S2 asked Milosz S2 commented

Creating labels by percentage in order

Hi I'm struggling with a problem involving label creation. On the source, I want them to create by percentage but I also want them to not be attached randomly but in order, f.e. first 20% type 1, next 30% type 2, next 35% type 3 etc. Is there a way that I can do it? Or maybe something to type in "Use random stream" field that will prevent random assigning? Thanks for help.

FlexSim 20.0.10
labelssourceobject creation
· 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.

Ryan Clark avatar image Ryan Clark commented ·

Hi @Milosz S2, was Joerg Vogel'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 0 ·
Milosz S2 avatar image Milosz S2 Ryan Clark commented ·
No, it wasn't helpful but I managed to do it on my own other way.
1 Like 1 ·

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Joerg Vogel commented

You don’t want a statistical distribution, you want a fixed ratio. In such scenario I recommend to setup an array of values which represent a ratio.

A really simple ratio would be

Array myratio = [1,2,3,4]; // four types equal distributed 

this array I assign to label. It is my default setup

Then I create items and choose randomly from this array an element by a discrete uniform distribution.

Array curRatio = myratio.clone(); 

This is my working array assigned to another label

int element = duniform(1,curRatio.length);
int nextType = curRatio[element];
curRatio.splice(element,1); // remove chosen element

if the working label array is empty of values, I fill it again from the default array.

An ratio of 2:1:1:1 would result in an Array of [1,1,2,3,4]. I think you get it now.

Your example is

4 times value 1; 5 times value 2; 7 times value 3; and so on.

Hint: my example is not a complete solution. It demonstrate how you achieve your aim. But the fun is, how you get it working yourself.

· 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.