Simulation with AnyLogic/Discrete Event Simulation/Bank Model/Step 6. Adding tellers

''' Step 6. Adding Tellers '''

Now we will create another part of the system by adding tellers that are working at the bank. Now some clients will come to see tellers, some – to access the ATM. We can model tellers using delays in the same way as we modeled ATM. However, modeling tellers using resources is much more convenient. Resource is a special unit that can be possessed by entity. Only one entity can possess a resource at a time; therefore entities compete for resources.

Modify the flowchart
 * 1) Add Service object. [[File:Step 6. Adding tellers 1.png]] Service seizes resource units for the entity, delays the entity, and releases the seized units. Modify the object properties:
 * 2) *There is one queue for all tellers. Set up Queue capacity to be of 20 places.
 * 3) *We assume that service time is triangularly distributed with the min value of 2.5, average value of 6, and the max value of 11 minutes. Set Delay time: triangular( 2.5, 6, 11 ) [[File:Step 6. Adding tellers 2.png]]
 * 4) Add ResourcePool object. ResourcePool object is storage for resource units. It should be connected to resource seizing and releasing objects (Service in our case). So connect it to the lower port of the service object. [[File:Step 6. Adding tellers 3.png]] Name the object tellers. Specify that this resource object has only four resource units: define its Capacity: 4 [[File:Step 6. Adding tellers 4.png]]
 * 5) Place SelectOutput object. SelectOutput object is a decision making block. The entity arrived at the object is forwarded along one of two output ports depending on the user-defined condition. Leave the default object properties. The entity routing condition randomTrue(0.5) defines that the number of customers competing for ATM and teller service will be approximately equal. Connect selectOutput and service to other objects as shown in the figure: [[File:Step 6. Adding tellers 5.png]]

Since the model changed, we need to alter the model animation as well.

Modify the animation
 * 1) Draw a polyline to animate the waiting customers queue. Draw it from left to right. Name the polyline queueBeforeTellers. [[File:Step 6. Adding tellers 6.png]]
 * 2) Draw a polyline with four points to the right of queueBeforeTellers. This polyline will indicate where teller animations are placed. Name it tellerPlaces. [[File:Step 6. Adding tellers 7.png]]

Now we will animate our tellers by defining two images representing tellers being idle and busy. AnyLogic will automatically switch between these images when the resource unit becomes seized and released.

Animate tellers
 * 1) Drag Image from the Presentation stencil to the place shown in the figure with a blue crossed rectangle. [[File:Step 6. Adding tellers 8.png]]
 * 2) Go to the Properties of the image shape. Name the image busyTeller.
 * 3) Define the image that this shape will display. Use Add Image button to add Teller Busy.png. You can find this file in the folder where Billing Department sample model is located (somewhat like \plugins\com.xj.anylogic.examples. \models\Billing Department). You will see the added image in the preview area. [[File:Step 6. Adding tellers 9.png]]
 * 4) Select the Original Size check box. If Original Size option is not selected, the picture is shown to fit the rectangle of the image shape, and otherwise the picture is shown without any distortions.
 * 5) Create one more image to show relaxing teller. Name it idleTeller and choose Teller Idle.png as the image displayed by this shape.

Now we will animate the flowchart by setting up animation properties of the flowchart objects.

Animate the model logic
 * 1) Now we need to animate customers queue. Therefore, modify the service properties:
 * 2) *Set queueBeforeTellers as Animation guide shape (queue) [[File:Step 6. Adding tellers 10.png]]
 * 3) To animate tellers, modify the tellers properties:
 * 4) *Specify tellerPlaces as Animation guide shape
 * 5) *Choose Set as Animation type
 * 6) *Set idleTeller as Idle unit animation shape
 * 7) *Set busyTeller as Busy unit animation shape [[File:Step 6. Adding tellers 11.png]]

In the current model the number of tellers is fixed. However, we may need to vary it dynamically at the model run time. AnyLogic provides a set of controls enabling changing the model parameters. Now we will add a slider to vary the number of tellers at run time.

Add a slider to vary the number of tellers
 * 1) Add a slider. Open the Controls stencil of the Palette and drag the Slider element from there into the graphical editor. Place it below our ResourcePool object to let the user know that this slider will vary the capacity of this particular object. [[File:Step 6. Adding tellers 12.png]]
 * 2) We want to vary the number of tellers in the system from 0 to 4. Therefore, set 4 as slider’s Maximum value.
 * 3) Type tellers.capacity as the slider's Default value.
 * 4) Specify tellers.set_capacity((int)value); as slider's Action. [[File:Step 6. Adding tellers 13.png]]

Run the model. You can see tellers being animated with our images. Now you can change the number of tellers with the slider. Therefore, you can see how many tellers you need for the specific customer arrival rate.