Overview
The UI control functions manage the user interface flow, from algorithm selection to simulation playback. These functions handle screen transitions, dynamic form generation, and simulation state management.Algorithm Selection
seleccionarAlgoritmo()
Selects a scheduling algorithm and transitions from the home screen to the input form.Algorithm type identifier. Valid values:
"fifo"- First In First Out"sjf"- Shortest Job First"rr"- Round Robin"prioridad"- Priority Scheduling"mlfq"- Multi-Level Feedback Queue
- Sets the global
algoritmoActualvariable - Hides the home screen (
pantallaInicio) - Shows the form screen (
pantallaFormulario) - Updates the algorithm title display
Input Generation
generarInputs()
Dynamically generates input fields based on the number of processes and selected algorithm.- Reads the number of processes from
numProcesosinput field - Validates that the number is positive
- Clears the
inputsdiv - Generates algorithm-specific inputs:
- Round Robin: Quantum field
- MLFQ: Quantum levels field (comma-separated)
- Priority: Priority field for each process
- Creates arrival time and CPU burst inputs for each process
- Adds a “Simular” button that calls
simular(n)
Simulation Execution
simular()
Collects input data, executes the selected algorithm, displays results, and prepares the timeline for animation.Number of processes to simulate
-
Data Collection:
- Reads arrival times and CPU bursts from input fields
- For Priority: collects priority values
- For Round Robin: reads quantum value
- For MLFQ: parses comma-separated quantum levels
-
Algorithm Execution:
- Calls the appropriate algorithm function:
fifo(llegada, cpu)sjf(llegada, cpu)roundRobin(llegada, cpu, quantum)prioridad(llegada, cpu, prioridades)mlfq(llegada, cpu, quantums)
- Calls the appropriate algorithm function:
-
Results Display:
- Shows the results section
- Calls
mostrarResultados()to render metrics table
-
Timeline Generation:
- For Round Robin:
generarTimelineRR(llegada, cpu, quantum) - For MLFQ:
generarTimelineMLFQ(llegada, cpu, quantums) - For others:
generarTimelineBasico(resultados, llegada)
- For Round Robin:
-
Simulation Reset:
- Calls
reiniciarSimulacion()to clear visual elements
- Calls
Simulation Controls
iniciarSimulacion()
Starts the step-by-step animation of the scheduling timeline.- Checks if
timelineGlobalhas data - Creates an interval that executes every 500ms
- Each interval:
- Calls
renderPaso()with the current timeline step - Increments
pasoActual - Stops when all steps are rendered
- Calls
pausarSimulacion()
Pauses the running simulation animation.- Clears the active interval
- Preserves
pasoActualso animation can resume from the same point
reiniciarSimulacion()
Resets the simulation animation to the beginning and clears all visual elements.- Clears the animation interval
- Resets
pasoActualto 0 - Clears visual elements:
- Gantt chart (
ganttLive) - Ready queue (
colaBox) - CPU display (
cpuBox) - set to ”-”
- Gantt chart (
- Called automatically by
simular()before starting a new simulation - Can be manually triggered by the Restart button
volverInicio()
Returns to the home screen and completely resets the application state.-
Stop Animation:
- Clears the simulation interval
-
Reset Variables:
pasoActual = 0timelineGlobal = []
-
Clear Visuals:
- Gantt chart
- Ready queue
- CPU display
- Results table (
salida) - Input fields container (
inputs) - Process number input (
numProcesos)
-
Screen Transition:
- Hides results section
- Hides form screen
- Shows home screen
Global State Variables
The UI control functions rely on these global variables:seleccionarAlgoritmo()setsalgoritmoActualsimular()populatestimelineGlobaliniciarSimulacion()createsintervaloSimulacionand incrementspasoActualreiniciarSimulacion()resetspasoActualvolverInicio()clears all state