SimulationBank implements a three-tier priority queue where customers are served based on priority level first, then arrival time (FIFO) within the same priority.
Defined in backend/src/customer/domain/priority.py:4:
class Priority(IntEnum): """ Enum: nivel de prioridad del cliente HIGH = 1 (adulto mayor, embarazada) MEDIUM = 2 (cliente preferencial) LOW = 3 (cliente regular) """ HIGH = 1 MEDIUM = 2 LOW = 3
# Add customer to waiting queueself.waiting_queue.append(customer)# Sort by priority (ascending), then arrival time (ascending)self.waiting_queue.sort(key=lambda c: (c.priority, c.arrival_time))
def _assign_free_teller(self) -> None: """ Busca secuencialmente si existe una ventanilla inactiva (IDLE). En caso de encontrar una y haber gente esperando, extrae al primer cliente de la fila y programa el evento SERVICE_START para esa ventanilla en el reloj actual. """ if not self.waiting_queue: return for t_id, teller in self.tellers.items(): if teller.status == "IDLE" or getattr(teller.status, "value", None) == "IDLE": next_customer = self.waiting_queue.pop(0) # Remove first (highest priority) # Schedule immediate SERVICE_START self.schedule_event(SimulationEvent(self.clock, EventType.SERVICE_START, customer=next_customer, teller_id=t_id)) return # Assign only one customer per call
1
Check if queue is empty
If no customers waiting, return immediately
2
Find idle teller
Iterate through tellers looking for status == IDLE
3
Pop highest priority customer
waiting_queue.pop(0) removes the first customer (sorted by priority, arrival_time)
4
Schedule SERVICE_START
Create immediate event (at current clock time) to begin service
The current implementation (list + sort) is simpler and performs well for typical queue sizes (<100 customers). For very large queues, consider the heap-based approach.
The frontend displays priority using color coding:
// frontend/src/queue/components/QueueNode.jsx (conceptual)const priorityColors = { 1: '#FF4444', // RED for HIGH priority 2: '#FFBB33', // YELLOW for MEDIUM priority 3: '#00C851' // GREEN for LOW priority}