How to represent "or" in By Case pickoption

yifei_wang
Not applicable
0 Views
9 Replies
Message 1 of 10

How to represent "or" in By Case pickoption

yifei_wang
Not applicable

[ FlexSim 16.0.1 ]

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?

604-picture.png

Accepted solutions (1)
1 View
9 Replies
Replies (9)
Message 2 of 10

regan_blackett
Not applicable

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.

Message 3 of 10

matthew_gillespie
Not applicable
Accepted solution

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.

605-bypercent.png

Here's the code behind it:

int randomnum = trunc(uniform(0.0, 100.0, 0));
double total = 0.0;

total += 33; 
if (randomnum <= total)
	return 1;
total += 33; 
if (randomnum <= total)
	return 2;
total += 34; 
if (randomnum <= total)
	return 3;
Message 4 of 10

yifei_wang
Not applicable

ok. It makes sense. But, is there another code similar to duniform but can include multiple discrete numbers?

0 Likes
Message 5 of 10

matthew_gillespie
Not applicable

The bernoulli() distribution will return one of two values based off a probability.

The dempirical() command does basically what the By Percentage pickoption code does, except you provide it a table of values and probabilities.

0 Likes
Message 6 of 10

regan_blackett
Not applicable

If @Matthew Gillespie's approach using the random number code doesn't do it for you, you could try dempirical("tablename") to chose your values by percentage. To use it, you would need to set up a table of values in a Global Table that has two columns and as many rows as possible values you want to chose from, set up like this:

PercentageValue
333
335
346

and call demprical like this:

int myvalue = demprical("GlobalTable1") 

The parmaeter passed must be the name of your table data. Fill in whatever percentage values you want to weight each value according to your needs.

Message 7 of 10

yifei_wang
Not applicable

Thank you, Regan!

Thanks, Matthew

Message 8 of 10

yifei_wang
Not applicable

thanks regan!

Message 9 of 10

mischa_spelt
Not applicable

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:

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

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

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

Or even in a single statement

int port = bernoulli(100/3, 3, duniform(5, 6)) 
// or bernoulli(100/3, 3, bernoulli(50, 5, 6))
0 Likes
Message 10 of 10

yifei_wang
Not applicable

thanks

0 Likes