README

wcx789ll/moonsim/scheduler does not have a README file

#
Job

pub(all) struct Job {
id : Int
arrival_time : Double
service_time : Double
deadline : Double?
priority : Int
status : JobStatus
start_time : Double?
finish_time : Double?
}

A schedulable unit of work.

Each Job carries:
  • id: globally unique integer identifier.
  • arrival_time: the simulation time (seconds) when the job entered the system.
  • service_time: the duration (seconds) the job requires on an executor.
  • deadline: optional absolute time limit (seconds); None means no deadline.
  • priority: scheduling priority �?lower values are processed first.
  • status: mutable lifecycle state.
  • start_time: set when execution begins.
  • finish_time: set when execution completes or is aborted.

#
Job::has_missed_deadline

fn Job::has_missed_deadline(self : Job, now : Double) -> Bool

Returns true if this job has missed its deadline. A job misses its deadline when its finish_time (or the current time, if still running) exceeds deadline.

#
Job::new

fn Job::new(id : Int, arrival_time : Double, service_time : Double, deadline : Double?, priority : Int) -> Job

#
Job::sojourn_time

fn Job::sojourn_time(self : Job) -> Double?

Returns the total sojourn time: time from arrival until the job finished. Returns None if the job has not yet finished.

#
Job::wait_time

fn Job::wait_time(self : Job) -> Double?

Returns the wall-clock waiting time: time from arrival until the job started running. Returns None if the job has not yet started.

#
JobQueue

pub(all) struct JobQueue {
discipline : QueueDiscipline
// private fields
}

A waiting queue backed by an array sorted according to a chosen discipline.

#
JobQueue::dequeue

fn JobQueue::dequeue(self : JobQueue) -> Job?

Dequeue the highest-priority job according to the current discipline. Returns None if the queue is empty.

#
JobQueue::enqueue

fn JobQueue::enqueue(self : JobQueue, job : Job) -> Unit

Enqueue a job in the position determined by the discipline.

#
JobQueue::is_empty

fn JobQueue::is_empty(self : JobQueue) -> Bool

#
JobQueue::length

fn JobQueue::length(self : JobQueue) -> Int

#
JobQueue::new

fn JobQueue::new(discipline : QueueDiscipline) -> JobQueue

#
JobQueue::peek

fn JobQueue::peek(self : JobQueue) -> Job?

Peek at the next job to be dequeued without removing it.

#
JobQueue::remove_by_id

fn JobQueue::remove_by_id(self : JobQueue, job_id : Int) -> Bool

Remove a specific job by id. Returns true if found and removed.

#
JobStatus

pub(all) enum JobStatus {
Queued
Running
Completed
Cancelled
DeadlineMissed
} derive(Eq,
Debug
)

Enumeration of all possible lifecycle states a Job can occupy.
impl Show for JobStatus

#
QueueDiscipline

pub(all) enum QueueDiscipline {
Fifo
Lifo
PriorityAscending
PriorityDescending
ShortestJobFirst
LongestJobFirst
EarliestDeadlineFirst
} derive(Eq,
Debug
)

Available queueing disciplines governing the order in which Jobs are dequeued from the waiting area.

#
Scheduler

pub(all) struct Scheduler {
name : String
executors : Int
busy_executors : Int
queue : JobQueue
event_manager :
EventManager

on_start : (Job) -> Unit
on_complete : (Job) -> Unit
on_cancel : (Job) -> Unit
on_deadline_miss : (Job) -> Unit
total_arrived : Int
total_completed : Int
total_cancelled : Int
total_deadline_miss : Int
total_wait_time : Double
total_service_time : Double
}

A discrete-event scheduler with configurable queuing discipline and a fixed pool of identical executor slots.

The scheduler integrates with the EventManager so that job start/finish transitions are automatically scheduled as simulation events.

#
Scheduler::cancel

fn Scheduler::cancel(self : Scheduler, job_id : Int) -> Bool

Cancel a queued (not yet running) job by id. Returns true if the job was found in the queue and cancelled.

#
Scheduler::free_executors

fn Scheduler::free_executors(self : Scheduler) -> Int

Return the number of free executor slots at the current simulation time.

#
Scheduler::mean_service_time

fn Scheduler::mean_service_time(self : Scheduler) -> Double

Return the mean service (execution) time across all completed jobs.

#
Scheduler::mean_wait_time

fn Scheduler::mean_wait_time(self : Scheduler) -> Double

Return the mean queuing wait time across all completed jobs. Returns 0.0 if no jobs have completed yet.

#
Scheduler::new

fn Scheduler::new(name : String, executors : Int, discipline : QueueDiscipline, event_manager :
EventManager
, on_start : (Job) -> Unit, on_complete : (Job) -> Unit, on_cancel : (Job) -> Unit, on_deadline_miss : (Job) -> Unit) -> Scheduler

#
Scheduler::queue_length

fn Scheduler::queue_length(self : Scheduler) -> Int

Return the current queue length.

#
Scheduler::submit

fn Scheduler::submit(self : Scheduler, job : Job) -> Unit

Submit a new job to the scheduler.

If a free executor is available, the job starts immediately; otherwise it enters the waiting queue. Deadline enforcement is scheduled as a separate simulation event when a deadline is present.

#
Scheduler::total_arrived

fn Scheduler::total_arrived(self : Scheduler) -> Int

Return total jobs that have arrived since the scheduler was created.

#
Scheduler::total_cancelled

fn Scheduler::total_cancelled(self : Scheduler) -> Int

Return total jobs cancelled before running.

#
Scheduler::total_completed

fn Scheduler::total_completed(self : Scheduler) -> Int

Return total jobs that completed before their deadline.

#
Scheduler::total_deadline_miss

fn Scheduler::total_deadline_miss(self : Scheduler) -> Int

Return total jobs that missed their deadline.