Is there a way to open ports with the same probability?

Is there a way to open ports with the same probability?

vanessa_buen_abad
Not applicable
8 Views
9 Replies
Message 1 of 10

Is there a way to open ports with the same probability?

vanessa_buen_abad
Not applicable

Is there a way to open 2 ports with the same probability? I have 2 racks connected in a queue and I would like the queue to open the port 1 with 50% of probability and the port 2 with the other 50%.

I have a model with 2 racks and a queue and this queue with an on entry trigger. When the entry trigger condition is true, I would like the rack1 to open its port with 50% of probability and rack 2 to open its port with 50% of probability. Can you help me please?

Here is the code:

treenode item = param(1); treenode current = ownerobject(c); int port = param(2); {

// ************* PickOption Start ************* // /***

treenode involved = /** \nObject: */ /***tag:object*//**/centerobject(current, 1)/**/; treenode involved2=centerobject(current,2); int condition = /** \nCondition: */ /***tag:condition*//**/true/**/; if (condition) { /** \nAction: *//***tag:action*//**/openoutput/**

(bernoulli(50, involved, involved2)); }

The errors say:

Invalid type for parameter 1 in call bernoulli()

Invalid type for parameter 2 in call bernoulli()

Invalid type for parameter 3 in call bernoulli()

Thanks you so much! @adrian haws

,

0 Likes
Replies (9)
Message 2 of 10

rodrigo_lamas
Not applicable

@Vanessa Buen Abad try to include more one number in your bernoulli distribution for the num stream. I hope can be helpfull for your model. Regards!

3934-example.png

0 Likes
Message 3 of 10

joerg_vogel_HsH
Mentor
Mentor

Highlighted an Object.

Quick Properties: Output > Send To Port > By Expression

Type: duniform(1,2,3)

The function duniform returns discrete random values in the interval [1..2] with random stream number 3. That gives you a probability 50% to 50% for port 1 and 2 of the object's output.

0 Likes
Message 4 of 10

vanessa_buen_abad
Not applicable

Thank you so much for your help! But for example, I am talking of an on entry trigger not only the send to port expression. Here´s a little more of explanation:

3937-f1.png

I have a queue with an on entry trigger and when the condition is true, I want to open the port of rack1 (center object 1) with a 50 probability and then with other 50 probability to open the port of rack 2 (center object 2). So that one time the port 1 open and the port 2 is closed and then the port 2 is open and the port 1 is closed.

I really appreciate your help, thank you so much

0 Likes
Message 5 of 10

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

Source code to add in the OnEntry-trigger:

treenode yourRack1 = centerobject(current,1);
treenode yourRack2 = centerobject(current,2);
if(duniform(0,1,3)) {   
   openoutput(yourRack1);   
   closeoutput(yourRack2);
}
else{
   openoutput(yourRack2);
   closeoutput(yourRack1);
}

You have to open and close the output of the racks vice versa at each entry event.

0 Likes
Message 6 of 10

vanessa_buen_abad
Not applicable

Thank you so much, it works!!!

0 Likes
Message 7 of 10

vanessa_buen_abad
Not applicable

Hello, lets suppose I want to do the same but now with 14 ports. In the same OnEntry trigger I would like to open port 1 and close from port 2 to 14 and then open port 3 for example and close port 1,2 and 4 to 14. Every port with the same probability to get open. I use this code by percentaje in the OnEntry trigger but it does not do what I want:

treenode item = param(1);

treenode current = ownerobject(c);

int port = param(2);

int stream =0;

double randomnum = uniform(0.0, 100.0, stream);

double total = 0.0;

treenode yourRack1= centerobject(current, 1);

treenode yourRack2= centerobject(current, 2);

treenode yourRack3= centerobject(current, 3);

treenode yourRack4= centerobject(current, 4);

treenode yourRack5= centerobject(current, 5);

treenode yourRack6= centerobject(current, 6);

treenode yourRack7= centerobject(current, 7);

treenode yourRack8= centerobject(current, 8);

treenode yourRack9= centerobject(current, 9);

treenode yourRack10= centerobject(current, 10);

treenode yourRack11= centerobject(current, 11);

treenode yourRack12= centerobject(current, 12);

treenode yourRack13= centerobject(current, 13);

treenode yourRack14= centerobject(current, 14);

total += 7.1428571429;

if (randomnum <= total){

openoutput(yourRack1); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total +=7.1428571429; }

if (randomnum <= total){

openoutput(yourRack2); closeoutput(yourRack1); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total +=7.1428571429; }

if (randomnum <= total){

openoutput(yourRack3); closeoutput(yourRack2); closeoutput(yourRack1); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429 }

if (randomnum <= total){

openoutput(yourRack4); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack1); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total +=7.1428571429; }

if (randomnum <= total){

openoutput(yourRack5); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack1); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){ openoutput(yourRack6); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack1); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack7); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack1); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack8); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack1); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack9); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack1); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack10); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack1); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14); total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack11); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack1); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){

openoutput(yourRack12); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack1); closeoutput(yourRack13); closeoutput(yourRack14);

total +=7.1428571429; }

if (randomnum <= total){

openoutput(yourRack13); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack1); closeoutput(yourRack14);

total += 7.1428571429; }

if (randomnum <= total){ openoutput(yourRack14); closeoutput(yourRack2); closeoutput(yourRack3); closeoutput(yourRack4); closeoutput(yourRack5); closeoutput(yourRack6); closeoutput(yourRack7); closeoutput(yourRack8); closeoutput(yourRack9); closeoutput(yourRack10); closeoutput(yourRack11); closeoutput(yourRack12); closeoutput(yourRack13); closeoutput(yourRack1);}

Can you please please help me?

0 Likes
Message 8 of 10

joerg_vogel_HsH
Mentor
Mentor

to make your code more readable: close on every entry all outputs!. Then open only the output of the randomly chosen range.

0 Likes
Message 9 of 10

vanessa_buen_abad
Not applicable

But my code is not working. Do you have idea what is wrong or why it isn't working? Or maybe another idea to do what I want? Anyway I'll do what you suggest to make it more readable. Thank you so much for that.

0 Likes
Message 10 of 10

ryan_jaynes
Not applicable

On super quick inspection your code won't work as expected because the line incrementing the total:

total += 7.1428571429;

Is inside of the if statement brackets, meaning it only gets incremented if the randomnum was less than or equal to it initially, in which case you don't even need to increment it. You can either move that line outside of the brackets after each if block or you could simply use the conditions

randomnum <= total * 1 ...

randomnum <= total * 2 ...

randomnum <= total * 3 ... etc...

I would try fixing that and see if it works after that.

0 Likes