The task can be accomplished using a priority queue where elements are sorted based on their importance in ascending or descending order.
The priority queue is a data structure that is very similar to a queue and it is used to manage data that has been assigned a priority. In a priority queue, items with higher priority get ahead of items with lower priority or based on the sequence data arrived. Priorities could be both i.e. in increasing and decreasing order.
## Levels Of Employees:
- Operator (Level - 1)
- Supervisor (Level - 2)
- Director (Level - 3)
In the scenario you described, the problem sounds like it might be best modeled by multiple queues, one for each role, rather than a single priority queue. We could pull calls off of the different queues based on the priority of the role. The operators would promise to offload as many calls as possible through a round-robin from their queue, followed by the supervisors, and then the directors if necessary.
### Operator
They will handle the calls first.
Q_opβ=β{c_1,βc_2,βc_3,ββ¦,βc_n}
Where Q_op denotes the queue of operators and c_i are the calls waiting in the queue.
### Supervisor
If all operators are busy, the call goes to Supervisor.
Q_spβ=β{c_nβ
+β
1,βc_nβ
+β
2,βc_nβ
+β
3,ββ¦,βc_2n}
Where Q_sp denotes the queue of supervisors.
### Director
If all operators and supervisors are busy, the call goes to Director.
Q_dirβ=β{c_2nβ
+β
1,βc_2nβ
+β
2,βc_2nβ
+β
3,ββ¦,βc_3n}
Where Q_dir denotes the queue of directors.
### Algorithm
Here is a pseudo-code that describes the logic of the call-handling process:
while (incoming_calls):
if not queue_operators.is_empty():
assign_call(queue_operators.dequeue())
elif not queue_supervisors.is_empty():
assign_call(queue_supervisors.dequeue())
elif not queue_directors.is_empty():
assign_call(queue_directors.dequeue())
else:
# Make the call wait in a queue
wait_queue.enqueue(incoming_call)
Here, βassign_call()β is a function to assign the call to the respective employee. And, βenqueue()β and βdequeue()β are basic queue operations to insert an element into the queue and remove an element from the queue respectively.
This way, every incoming call will be directly assigned to an operator unless all operators are busy. The call will be then escalated to the supervisor if all operators are currently busy. If supervisors are also busy, then it will be escalated to directors.
If all three levels are busy at the moment, the incoming calls will wait in a separate queue until they get a free slot from any of the three levels (i.e., Operator, Supervisor, and Director).
The model assumes calls are serviced one by one, and the hierarchy is strict, i.e., an available supervisor wonβt pick a call if there is any operator free. This guarantees that calls are handled at the lower level possible.
This model can be enhanced by time slicing or allowing higher levels to pick calls if they have been idle for too long, but those details depend on the business rules of the call center.