0
votes

I have the following simple model of a hospital HospitalModel. I am trying to generate an Output statistic for my model at the simulation end time, e.g., the porcentage of patients seen by a nurse. I first tried using an Output "On simulation end" stat with the value nurseService.count()/patientArrival.count() as I am trying to calculate the value without generating new variables but I realized this expression gives 0 at simulation end time. Then I tried generating a variable porcentageNurse and updating it with an event every hour with the expression nurseService.count()/patientArrival.count(), but once again, I realized the calculation was never computed.

  1. Why doesn't Anylogic compute this operation?

Afterwards I realized a way to make it work is to compute first nurseService.count() and save its value into a variable 'a' and then use the expression: a/patientArrival.count(). This works if you update a variable with an event, but in the Output stat case, local variables can't be defined in the value field so again it can't be done directly.

  1. There is any way to output such an statistic as the percentage of patients without creating adittional variables?

Finally, I realized other than with the Output stat, I couldn't find a way to run code at simulation end time (or generate statistics at simulation end time). There is an "After simulation run" section in the java actions of the simulation experiment, but it seems this section is not connected with main.

  1. How can you connect this section to main? Or which would be the proper way to run code at simulation end time? Is there a way to generate statistics at simulation end time without the Output stat?

  2. Is there an expression to call the simulation end time?

    Thanks for your help.

1

1 Answers

2
votes

nurseService.count() and patientArrival.count() are of type long, and when you make any arithmetic with longs or ints, the resulting value is an int.

so if you devide 45/58 for example, the result is truncated to 0.

So what you need to do instead is for at least one of the variables to be a double:

(double)nurseService.count()/patientArrival.count()

And for your second question, for After simulation run, instead of main, you can use root, so if the variable name in main is var, you can access it using root.var