I have a resource named "Docks", its capacity is 14, I want to calculate the total time for which all the 14 docks are busy? Is there any way, please help.
1 Answers
I will propose a solution that may not be the most efficient one. However, it will at least guide you in the right direction. One way to do it is to create an event with the following code, noting that timeBusy
would be a variable of type double:
if( resourcePool.busy() == resourcePool.size() ) {
timeBusy++;
}
Make the event of type cyclic. If you make it cyclic every second, the timeBusy
variable would give you the time all resources are busy in seconds. The issue with this method is:
- The smaller the cycle time, the slower the model becomes (although this line of code may not be that of an issue)
- The bigger the cycle time, the lower the accuracy of the measured time.
Alternatively, a more advanced solution would be to use the On Seize
and On Release
fields of the resource pool, where you can add your code to check the number of busy units each time a resource is seized or released only and not every cycle time. The main idea of this method would be to use three variables: startTime
and totalTime
of type double and start
of type boolean with an initial value of false
. So On Seize
you would write:
if( resourcePool.busy() == resourcePool.size() && !start ) {
startTime = time();
start = true;
}
And On Release
:
if( resourcePool.busy() == resourcePool.size() - 1 && start ) {
totalTime += time() - startTime;
start = false;
}
You may need to validate the results, but this should at least put you in the right direction.
The only downside of this method is that results are only updated when a resource is seized or released. So if for example, all your resources are seized for a long time, you may not see any changes to the variables.
Depending on your model, you can judge which method works better for you.
One final note is that you can opt to have a hybrid method to ensure live updates and 100% accuracy.
I would personally go for the first method if your model is relatively simple.

- 2,161
- 2
- 6
- 18