javaanylogicdiscrete

How can I obtain the number of times that a hold block changes its state?


I am modelling a supply chain process. The case is that when the wait block reaches its maximum capacity I block the hold block in order to stop the flow of components and when one component exits the wait block I unblock the hold . What I am trying to calculate is:

  1. How much time is the hold in the block state during the whole simulation ( time()).
  2. The number of times that this hold block changed its state from unblocked to block during the simulation (count)

I tried to calculate this using events but the results that I am obtaining are not correct.Could you give me a hand with this? Thanks!

Screenshot of the actual model


Solution

  • Create two variables of type double and call them timeBlocked and blockStartTime (initial value = 0). Also create a variable called blockCount. This one can be of type int (initial value = 0 too).

    In your code, every time you block the hold block, add the following line:

    blockStartTime = time();
    blockStart++;
    

    Every time you unblock it, add the following:

    timeBlocked += time() - blockStartTime;
    

    Now as an extra note, I can see you have more than one hold block, so I would recommend doing the above for each one (i.e. create the variables I suggested twice, once for each block). If you have a ton of hold blocks and you provide more details, we may be able to give you a leaner solution, but I guess the above should work well enough for your model.