classes

All topics on coding 4Dscript in Enterprise Dynamics.
MarvinH
Posts: 93
Joined: Tuesday 25 January, 2011 - 11:07
Contact:

Re: classes

Post by MarvinH »

Hello!

For the sake of readability, I have created a small piece of code in which the notation is similar to your report.

Code: Select all

Do(
  Var([valUniform], vbValue, Uniform(0, 1)),
  Var([valP1], vbValue, 0.3),
  Var([valP2], vbValue, 1 - valP1),
  Var([valN1], vbValue, Content(In(1,c))),
  Var([valN2], vbValue, Content(In(2,c))),
  Var([valAverageN1], vbValue, AvgContent(In(1,c))),
  Var([valAverageN2], vbValue, AvgContent(In(2,c))),
  
  OpenIC(
    If(
      valUniform < (valN1 * valP1) / (valN1 * valP1 + valN2 * valP2),
      1,
      2
    ),
    c
  )
)
You can define your value for valP1 (0.3 in the example above), valP2 is defined automatically.

Note that the values of valN1 and valN2 are now defined by the current content of the queues connected to input channel 1 and 2 respectively. I have also added the variables valAverageN1 and valAverageN2, which are defined by the average content of the queue connected to input channels 1 and 2 respectively. You can change the formula by replacing valN1 by valAverageN1 and valN2 by valAverageN2 in case you want to use average content instead of current content.

Hope this works out for you!

Kind regards,

Marvin
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

Marvin, thank you very much... It works great. Also thank you for including the ''avg'', but in this ''queue'' system I just want a ''hard'' p - value and a switching length of queue. In this situation, a queue with a very long ''tail'' will be served with a great probability!.

But, there is a strange thing. First of all, in the beginning it could be that you gonna divide by zero, so I included in the denominator a 0.0000000000001 extra. So then it is always a ''true'' value. Furthermore, If the first product is part of queue 2, but I choose p1 = 1, then he will choose the product out of queue 2, because the uniform generator is always >0, so will take queue 2, but p1 =1, how can i deal with this?
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

I already found a solution :

Do(
Var([valUniform], vbValue, Uniform(0, 1)),
Var([valP1], vbValue, 1),
Var([valP2], vbValue, 1 - valP1),
Var([valN1], vbValue, Content(In(1,c))),
Var([valN2], vbValue, Content(In(2,c))),
Var([valAverageN1], vbValue, AvgContent(In(1,c))),
Var([valAverageN2], vbValue, AvgContent(In(2,c))),


if(valN1>0, OpenIC(
If(
valUniform < (valN1 * valP1) / (0.00000000000000000000000001 + valN1 * valP1 + valN2 * valP2),
1,
2
),
c
), OpenIC(
If(
valUniform >= (valN2 * valP2) / (0.00000000000000000000000001 + valN1 * valP1 + valN2 * valP2),
1,
2
),
c
) )



)

But, i dont know of it works well. For the situation p1 = 1 or p2 = 1, it works well, because, assume lambda = 0.25 en mu = 1, then you expect a lengthqueue of the system of 0.25 / (1-0.25) = 1/3 and indeed ED say yes to it!
But in the situation p1 = 0.999999999 you expect nearly the same, because nearly never you go to queue 2, so then the length should be around the same, but i will differ a lot. Do you have any idea about that?
MarvinH
Posts: 93
Joined: Tuesday 25 January, 2011 - 11:07
Contact:

Re: classes

Post by MarvinH »

Hello!

I think the unexpected behaviour is caused by situations where the numerator or denominator equals zero. I would prefer another solution for situations where the dominator would equal zero, instead of the correction factor. I think that you should know beforehand what the behaviour should be in cases where either the numerator or denominator equals zero. There are four situations with respect to numerator and denominator:

- valN1 * valP1 = 0 and valN2 * valP2 = 0;
- valN1 * valP1 = 0 and valN2 * valP2 > 0;
- valN1 * valP1 > 0 and valN2 * valP2 = 0;
- valN1 * valP1 > 0 and valN2 * valP2 > 0.

I think that you should change your script to deal with these four situations. The script I posted earlier is for the last situation, maybe you can devise similar code for the other situations, depending on how the system should behave in these particular situations. For example:

Code: Select all

If(
  And(
    valN1 * valP1 = 0,
    valN2 * valP2 = 0
  ),
  ...
)
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

Hello, thank you I attached my ED file. I now have the idea that the machine is looking more times than a products arrives...

The situation that i really want is that: ok, start situation there is nothing, and i wait till a products arrives, ok, then length of queue 1 (for example ) is one en probability is 0,7 then wil change 0,7 i wil take it, if I generate 0,8 then i try again untill i will process someting. In the case with p1 = 1 then the queue 2 will grow fast and fast...

But now, the situation is again (for p1 = p2 = 0.5) not equal in case of the queue length. Maybe i am doing something very strange, but i dont now what exactly! I hope you can help me again! thank you..
Attachments
try1.mod
(23.71 KiB) Downloaded 305 times
MarvinH
Posts: 93
Joined: Tuesday 25 January, 2011 - 11:07
Contact:

Re: classes

Post by MarvinH »

Hello again!

Maybe it is good to know how the "Input strategy" in Enterprise Dynamics works in general. The input strategy is triggered after the server is done with a product. Then the input strategy is executed to determine which input channel should be opened for the next product. This is only done once. So in case you have one product in Queue1 with a corresponding probability of 0.7, what should happen when the input strategy is evaluated and the drawn value from the uniform distrubution equals 0.8? Should input channel 2 be opened, where no product is present? Or should no channels be opened at all? Note that an input channel remains open until a product has been received through this particular channel.

I assume that you do not want to open an input channel in the situation described above. So, to open the channel again, you should "trigger the server" again when a product arives in one of the queues and there is no product present in the server. To do this, put the following code on the Entry trigger of both Queues:

Code: Select all

If(
  Content(Out(1,c)) = 0,
  CreateEvent(0, Out(1, c), 3)
)
I have implemented the changes described above in your attached model already. Further I have put some traces in the code (which are printed in the Tracer window, available through Window -> Tracer), in order to be able to see which part of the code is executed.

Tip: Use "Ctrl + R" to view the open/close (= green/red) status of the channels in combination with the Step-button on the Run Control.

Good luck!

Regards,

Marvin
Attachments
try2.mod
Implemented changes to the previous model.
(25.44 KiB) Downloaded 301 times
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

Marvin, thank you, thank you... now it works perfects, because we know for little law:

L = rho/ (1 - rho) and rho = 0.5 for the whole system, so L = 1, so L = 1/2 for every queue. And I obain now 0.25 for every queue stay (from your try2), and that is correct, because L_q (length queue) = 0.5 - 0.25 = 0.25. Wow it works! :D

Now i am trying to count the actual stock in the system (with this priority system). Lets assume that i have a stock of 15 products and if a products arrives then the stock is 15 - 1 = 14. After finishing a product at the machine the stock will go back to 15. I want to count the actual stock, so actual stock = stock - # in queue - product at machine.

I was thinking (before reranging everyting) introduce variable valS1 (but where can i do it the best? queue, not source i guess?) and then bij queue, if input then valS1 = valS1 - 1. and output machine = valS1 = valS1 - 1. And then i want of course somethin average of the actual stock. but now the stock is calculated at every time. How should I do something like that?
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

Marvin, this is what i created, but now i only put a count in a table so, 0 and something it is 1,2 or 3 and then again 0. But it would be better if it is 15 - .... so startvalue of 15 (i could not fix that...) and how can i get the average? because i can not simply sum it up and devide it by time, because when should I sum it up? every second or every 10 sec. how can i deal with that?
deltroya
Posts: 21
Joined: Monday 26 December, 2011 - 15:11

Re: classes

Post by deltroya »

deltroya wrote:Marvin, this is what i created, but now i only put a count in a table so, 0 and something it is 1,2 or 3 and then again 0. But it would be better if it is 15 - .... so startvalue of 15 (i could not fix that...) and how can i get the average? because i can not simply sum it up and devide it by time, because when should I sum it up? every second or every 10 sec. how can i deal with that?
Attachments
try3.mod
(28.12 KiB) Downloaded 299 times
User avatar
MatthijsJongboer
Posts: 200
Joined: Thursday 11 November, 2010 - 14:12

Re: classes

Post by MatthijsJongboer »

Marvin, thank you, thank you... now it works perfects, because we know for little law:

L = rho/ (1 - rho) and rho = 0.5 for the whole system, so L = 1, so L = 1/2 for every queue. And I obain now 0.25 for every queue stay (from your try2), and that is correct, because L_q (length queue) = 0.5 - 0.25 = 0.25. Wow it works! :D
Excellent.
That closes this topic. Please start a new thread for the stock issue.
Post Reply