classes

All topics on coding 4Dscript in Enterprise Dynamics.
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

classes

Post by deltroya »

Hello everyone,

I have the following question :

Suppose the follow situation : I have two queues, both with an exponential arrival rate and both have the same exponential processing time (let assume \mu = 1, and lambda1 = 1/4 and lambda2 = 1/4).

Now, I will not take a product out of the queue on basis of some random generation, but based on the following principal:

choose two paramters p1, p2 such that p1+p2 = 1, thus p1 = 0.7 and p2 = 0.3

Now, I will choose a product out of queue 1 with probability:

p1 * n1 / (p1 * n1 + p2 * n2) ,

with n1, n2 the length of queue 1 , queue 2 respectively.

For programming this into ED, it is (i guess) easy to introduce such p'values, because you can say simply 0,7 * ... etc. but, how can i call the length of a queue? And how to ''say'' that the have to take queue 1 with probability (as given below)?

Thank you in advance!
User avatar
MatthijsJongboer
Posts: 200
Joined: Thursday 11 November, 2010 - 14:12

Re: classes

Post by MatthijsJongboer »

It seems that what you are looking for is an input strategy for the object calling the products from both queues. If this object has two input channels (one for each queue), you have a reference to both queues. You code on the input strategy can do the job. To get the length of the queues you can use content(in(1,c)) and content(in(2,c)).

Now you need to define your strategy principal that opens one of these channels (the result). You can have a look at existing functionality. To do so, take a server atom, open the GUI and select 'input strategy'. You will see a drop-down so select one of the options. You will see that the dropdown is selected and remains open. On the right hand side you will find a small square with helptext 'push to edit as 4DScript'. When you push this button, you will see the 4DScript equivallant to the textual discription. Here you can write your own code. Nota that your code requires the 4DScript command 'openic' actually opening the resulting input channel.
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

thank you. Indeed the situation is with two queues, and one server. But is it enough to state:

p1 = 0.3
p2 = 0.7 (not in script)

openic(0,3 * contect(in(1,c)) / 0,3 * contect(in(1,c)) + 0,7 * contect(in(2,c)) , ...... here for queue 2? )

Will the inputsystem then take a product out of queue 1`with the stated probability as given above?

thank you in advance!
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

I should think:

uniform between 0 and 1 (how can i call this?)
then:

openic( if(0,3 * content(in(1,c)) / (0.3 * content(in(1,c)) + 0.7 * content(in(2,c))) <= uniform),1,2 ,c)

So, if the if - statement is true, then take queue 1, otherwise, take queue 2. It doesnt work right now, because i dont know how the implement a uniform generator and then if the code works. Maybe you can help me a little bit? thank you!
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

deltroya wrote:I should think:

uniform between 0 and 1 (how can i call this?)
then:

openic( if(0,3 * content(in(1,c)) / (0.3 * content(in(1,c)) + 0.7 * content(in(2,c))) <= uniform),1,2 ,c)

So, if the if - statement is true, then take queue 1, otherwise, take queue 2. It doesnt work right now, because i dont know how the implement a uniform generator and then if the code works. Maybe you can help me a little bit? thank you!
Please see the attached file!
ED_1.mod
(23.09 KiB) Downloaded 317 times
User avatar
MatthijsJongboer
Posts: 200
Joined: Thursday 11 November, 2010 - 14:12

Re: classes

Post by MatthijsJongboer »

maybe you can store them in 2 local variables like this:
do(
var([p1], vbValue, Uniform(0, 1)),
var([p2], vbValue, 1-p1),
...
)
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

Thank you, but i already included the uniform distribution in thefile. But i have THE idea that i doenst work well, can you please check this file?
User avatar
MatthijsJongboer
Posts: 200
Joined: Thursday 11 November, 2010 - 14:12

Re: classes

Post by MatthijsJongboer »

Well, you place the label on the involved atom (which will not work on the input strategy, only on the trigger on entry and exit).
But you use the label from c. So the first change will be putting it on c.
What could be helpul is the 4DScript interact window. Here you can try chuncks of code and see what the result is. The code Uniform(0,1) will return a value between 0 and 1. You check if it is smaller then 2 which will always be the case. In addition, you placed the label on i so the call Label([uniform],c) will return 0.
Now you have your code in place to hang a probability to it.
Your code could look like this:

Code: Select all

Do(
 Label([uniform],c):=Uniform(0, 1),
 openic(
  if(
   Label([uniform],c)<(0.5),
   1,
   2
  ),
  c
 )
)
You should have a look at the probability.
Also know that the code is triggered to open the input so you could profit from readible code like:

Code: Select all

Do(
 var([p1], vbValue, Uniform(0, 1)),
 var([p2], vbValue, 1-p1),
 var([content1], vbValue, Content(in(1,c))),
 var([content2], vbValue, Content(in(2,c))),
 /(
  (*(p1, content1)),
  (+(
    *(p1 , content1),
    *(p2, content2)
   )
  )
 )
)
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

thank you Matthijs, so I can best use the second script? And for my situation I have to check if the generation of the uniform dist. is smaller then:

n1 * p1 / (n1 * p1 + n2 + p2),

where n1 = length of queue 1, p1 and p2 given probabilities, so i can choose them by myself. Can i implement that with

content(in(1,c)) for queue 1?
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

I now wrote down the following script:

Do(
Label([uniform],c):=Uniform(0, 1),
openic(
if(
Label([uniform],c)<((0.5*content(in(1,c)))/(0.0000000000001 + (0.5*content(in(1,c)) + 0.5 * content(in(2,c))))),
1,
2
),
c
)
)

I included 0.000001 to be sure that it is not possible to divide by 0. Further, the 0.5 and 0.5 are the p - values, they should be choosen randomly, so 0.3 and 0,7 and so on. I am not sure of the systems is working well at the moment, but how can i measure the 'length'' of the queue? (or better the average length of the queue, so on the long run)
Post Reply