Overview
Timeline generation functions convert scheduling algorithm results into frame-by-frame animations. Each function produces an array of timeline steps showing the CPU state, executing process, and ready queue at each time unit.Timeline Structure
All timeline functions return an array of step objects:Basic Timeline
generarTimelineBasico()
Generates a simple timeline for non-preemptive algorithms (FIFO, SJF, Priority).Algorithm execution results containing:
inicio(array): Start time for each processfinalizacion(array): Completion time for each processespera(array): Wait time for each processretorno(array): Turnaround time for each processtiempoTotal(number): Total execution time
- Find the maximum completion time (
tiempoMax) - For each time unit from 0 to
tiempoMax:- Search for a process where
inicio[i] ≤ t < finalizacion[i] - Set
ejecutandoto the found process ID (or null) - Set
colato empty array (queue not tracked for basic algorithms)
- Search for a process where
tiempo, ejecutando, and cola properties.
Example:
- FIFO algorithm visualization
- SJF algorithm visualization
- Priority scheduling visualization
Round Robin Timeline
generarTimelineRR()
Generates a detailed timeline for Round Robin scheduling with quantum-based preemption and queue tracking.Array of arrival times for each process
Array of CPU burst times for each process
Time quantum for Round Robin scheduling
- Initialize processes with remaining CPU time
- Maintain a ready queue
- For each time unit:
- Add newly arrived processes to the queue
- If queue is empty, advance time (CPU idle)
- Dequeue the first process
- Execute for min(quantum, remaining time) units:
- Record timeline step at each unit
- Decrement remaining time
- Check for new arrivals during execution
- If process not complete, re-enqueue at the end
- If complete, increment completed counter
- Continue until all processes are complete
- Processes added to queue when they arrive and CPU becomes available
- FIFO queue ordering
- Preempted processes go to the back of the queue
- New arrivals during execution are added immediately
simular() when algoritmoActual === "rr".
MLFQ Timeline
generarTimelineMLFQ()
Generates a complex timeline for Multi-Level Feedback Queue scheduling with dynamic priority levels.Array of arrival times for each process
Array of CPU burst times for each process
Array of time quantums for each priority level (e.g.,
[2, 4, 8] for 3 levels)-
Initialize processes with:
- Remaining CPU time
- Current priority level (starts at 0)
- Queue membership flags
- Create multiple queues (one per quantum level)
-
For each time unit:
- Add newly arrived processes to queue 0 (highest priority)
- Find the highest-priority non-empty queue
- If all queues empty, CPU is idle
- Dequeue process from highest-priority queue
- Get quantum for current level
- Execute for min(quantum, remaining time) units:
- Record timeline step with all queue states
- Decrement remaining time
- Check for new arrivals (added to queue 0)
- After quantum expires:
- If process complete: mark as terminated
- If incomplete: demote to next lower level (or stay at lowest)
- Continue until all processes complete
- Queue 0: Highest priority (smallest quantum)
- Queue N-1: Lowest priority (largest quantum)
- Always serve from highest-priority non-empty queue
- New processes start at level 0
- After using full quantum without completing, demote to next level
- Processes at lowest level stay there
- New arrivals always enter at level 0 (highest priority)
simular() when algoritmoActual === "mlfq".
Timeline Rendering
renderPaso()
Visually renders a single timeline step to the UI.Timeline step object containing:
tiempo(number): Current time unitejecutando(number|null): Process ID in CPU or null if idlecola(number[]|number[][]): Process IDs in ready queue(s)
-
CPU Display:
- If
ejecutando === null: show “Idle” - Otherwise: show “P” (e.g., P1, P2)
- If
-
Queue Display:
- Clear the queue container
- For each process ID in
cola:- Create a styled div with “P”
- Apply animation classes
- Append to queue container
-
Gantt Chart:
- Create a new block for this time unit
- Show process ID or ”-” for idle
- Apply hover and transition effects
- Append to Gantt chart
- Auto-scroll to show latest block
cpuBox: CPU state displaycolaBox: Ready queue containerganttLive: Gantt chart timeline
- Queue items:
bg-gray-700 px-3 py-1 rounded-lg shadow animate-pulse - Gantt blocks:
w-8 h-8 bg-indigo-500 rounded flex items-center justify-center - Hover effect:
hover:scale-110with smooth transition
iniciarSimulacion() every 500ms during animation playback.
Timeline Comparison
| Feature | Basic | Round Robin | MLFQ |
|---|---|---|---|
| Queue tracking | No | Yes (single) | Yes (multi-level) |
| Preemption | No | Yes | Yes |
| Complexity | O(T) | O(T×N) | O(T×N×L) |
| Use case | FIFO, SJF, Priority | RR algorithm | MLFQ algorithm |
- T = Total execution time
- N = Number of processes
- L = Number of queue levels