Simulation with AnyLogic/Discrete Event Simulation/Bank Model/Step 7. Collecting customer time statistics

''' Step 7. Collecting Customer Time Statistics '''

We want to know how much time customer spends waiting in ATM queue and the whole time he spends in the bank. We will collect time statistics using AnyLogic analysis data objects and observe the resulting time distributions using histograms.

First, we will create new entity class Customer to represent customers in our model. This class will have parameters to carry the required time information.

Define Customer Java class
 * 1) Right-click model item and choose New|Java Class from the popup menu. [[File:Step 7. Collecting customer time statistics 1.png]]
 * 2) This opens New Java Class dialog. Type the name of the new Java class: Customer. Specify that Customer is derived from Entity. Therefore, select com.xj.anylogic.enterprise.Entity from the Superclass drop-down list. [[File:Step 7. Collecting customer time statistics 2.png]]
 * 3) Click Next to open the next page of the wizard. On the second page of the wizard, define the parameters of the class. Create startWaiting parameter of type double to store the time when the customer starts waiting in the ATM queue. [[File:Step 7. Collecting customer time statistics 3.png]]
 * 4) Click Finish. You will see the code editor for the created class opened. Type double enteredSystem; in the class body to define one more class parameter. This parameter will store the time when the customer enters the bank department. [[File:Step 7. Collecting customer time statistics 4.png]]
 * 5) When finished, close the code editor by clicking on the “cross” button in the upper right corner of the editor.

Add histogram data objects to store statistics on customer's waiting time and time in system. Histogram data objects support standard statistical analysis on the data values being added (calculate mean, minimum, maximum, deviation, variance and mean confidence interval).

Add histogram data objects to collect time statistics
 * 1) To add histogram data object on the diagram, drag the Histogram Data from the Analysis stencil of the Palette onto the class diagram.
 * 2) Set up the properties of the element.
 * 3) *Change the Name to waitTimeDistr.
 * 4) *Change the Title to Waiting time distribution.
 * 5) *Set the Number of intervals equal to 50.
 * 6) *Set the Initial interval size: 0.01. [[File:Step 7. Collecting customer time statistics 5.png]]
 * 7) Create one more histogram data object. Ctrl+drag histogram data object to create its copy. Change the Name to timeInSystemDistr. Change the Title to Time in system distribution. [[File:Step 7. Collecting customer time statistics 6.png]]

Now we will modify properties of our flowchart objects.

Modify the properties of the flowchart objects
 * 1) Modify source properties:
 * 2) *Specify new Customer as New entity. Now this object wiil generate entities of our Customer class. Type Customer in Generic parameters field. This enables direct access to the fields of the Customer entity in the dynamic parameters of this object.
 * 3) *Type entity.enteredSystem = time; in On exit. This code stores the time when a customer was generated in the Customers variable enteredSystem. The time function returns the current model time.
 * 1) Modify queue properties:
 * 2) *Type <tt>Customer</tt> in Generic parameters field.
 * 3) *Type <tt>entity.startWaiting = time;</tt> in On enter. This code stores the time when a customer started waiting in the queue in the Customer's variable <tt>startWaiting</tt>.
 * 4) *Type <tt>waitTimeDistr.add(time - entity.startWaiting);</tt> in On exit. This code adds waiting time of the customer to the <tt>waitTimeDistr</tt> histogram data object.
 * 1) Modify sink properties:
 * 2) *Type <tt>Customer</tt> in Generic parameters field
 * 3) *Type <tt>timeInSystemDistr.add(time-entity.enteredSystem);</tt> in On enter. This code adds the whole time the customer spent in the bank to the <tt>timeInSystemDistr</tt> histogram data object.

Run the model and view the statistics using inspect window of the data set. Open inspect window for data set by clicking on it. Here you can see standard statistical analysis on the data values being added to this data object.



Now we want to display the collected statistics using standard histograms.

Add two histograms to display distributions of customer's waiting time and time in system
 * 1) To add histogram on the diagram, drag the Histogram element from the Analysis stencil of the Palette onto the class diagram where you want to place the histogram. [[File:Step 7. Collecting customer time statistics 11.png]]
 * 2) Define the data object to be displayed by this histogram. Click the Add Histogram Data button and specify the Histogram to be displayed: waitTimeDistr. [[File:Step 7. Collecting customer time statistics 12.png]]
 * 3) Add one more histogram below the existing one.
 * 4) Choose the data object to be displayed: timeInSystemDistr.
 * 5) Change the Title of the displayed data to Time in system distribution.

Run the model. Set virtual time mode and observe distribution of customer's time in system and waiting time.