question

Yifei Wang avatar image
1 Like"
Yifei Wang asked Brandon Peterson edited

How to represent "or" in By Case pickoption

Hi,

Please see the attached picture. "||" does not work in my code. I would like the source to randomly assign itemtype2 to Port 3,5, or 6. It seems duniform only assigns a random number between min and max. Is there a way to represent "or" in FlexSim?

FlexSim 16.0.1
flexscriptcodeportsby case
picture.png (159.6 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Yifei Wang commented

Take a look at this By Percentage pickoption. You could use the code it uses in your break statement. It generates a number between 1 and 100 and, depending on what number it is, chooses a return value. For example, if the random number is a 10 it will return 1 since 10 < 33.

Here's the code behind it:

  1. int randomnum = trunc(uniform(0.0, 100.0, 0));
  2. double total = 0.0;
  3.  
  4. total += 33;
  5. if (randomnum <= total)
  6. return 1;
  7. total += 33;
  8. if (randomnum <= total)
  9. return 2;
  10. total += 34;
  11. if (randomnum <= total)
  12. return 3;

bypercent.png (26.9 KiB)
· 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.

Regan Blackett avatar image
2 Likes"
Regan Blackett answered Yifei Wang commented

Just like in your other question you can't use the logical relation operator for OR or AND like that. It's the right symbol but incorrectly used. The result of an OR or AND expression is always true or false represented as zero (false) and one (true). So the logical result of 3|| 5 || 6 is 'true' not one of the three values. In order to chose one of the values to assign to your variable you need a method that assigns it based on some kind of condition or algorithm. How is value 3, 5, or 6 selected? Under what conditions in the model?

What your describing, having the source send things that are type 2 to either ports 3, 5, 6, you either need to tell the queues connected to that port to pull item type 2, or write condition statements that says why you would select ports 3 vs 5 vs 6.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Mischa Spelt avatar image
0 Likes"
Mischa Spelt answered Yifei Wang commented

If you want to draw 3, 5 or 6 with equal probabilities, you can put them in an array and use duniform to draw the position (index) in the array:

  1. intarray ports = makearray(3);
  2. fillarray(ports, 3, 5, 6);
  3. int randomPort = ports[duniform(1, arraysize(ports))];

Or, in this particular case, you can use that you have almost-contiguous values:

  1. int port = duniform(4, 6);
  2. if(port == 4) { port = 3; }

Or even in a single statement

  1. int port = bernoulli(100/3, 3, duniform(5, 6))
  2. // or bernoulli(100/3, 3, bernoulli(50, 5, 6))
· 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.