Skip to main content

u_schedule/dispatching/
mod.rs

1//! Dispatching rules and rule engine for scheduling.
2//!
3//! Provides priority-based dispatching rules (SPT, EDD, ATC, etc.)
4//! and a composable rule engine for multi-criteria task prioritization.
5//!
6//! # Usage
7//!
8//! ```
9//! use u_schedule::dispatching::{RuleEngine, SchedulingContext};
10//! use u_schedule::dispatching::rules;
11//!
12//! let engine = RuleEngine::new()
13//!     .with_rule(rules::Edd)
14//!     .with_tie_breaker(rules::Spt);
15//!
16//! let context = SchedulingContext::at_time(0);
17//! // let sorted = engine.sort(&tasks, &context);
18//! ```
19//!
20//! # References
21//!
22//! - Pinedo (2016), "Scheduling: Theory, Algorithms, and Systems", Ch. 4
23//! - Haupt (1989), "A Survey of Priority Rule-Based Scheduling"
24
25mod context;
26mod engine;
27pub mod rules;
28
29pub use context::SchedulingContext;
30pub use engine::{EvaluationMode, RuleEngine, TieBreaker};
31
32use crate::models::Task;
33use std::fmt::Debug;
34
35/// Score returned by a dispatching rule.
36///
37/// Lower scores = higher priority (scheduled first).
38/// This follows the academic convention where SPT = shortest processing time first.
39pub type RuleScore = f64;
40
41/// A dispatching rule that evaluates task priority.
42///
43/// # Score Convention
44/// **Lower score = higher priority.** Rules should return smaller values
45/// for tasks that should be scheduled first.
46///
47/// # Reference
48/// Pinedo (2016), "Scheduling", Ch. 4: Priority Dispatching
49pub trait DispatchingRule: Send + Sync + Debug {
50    /// Rule name (e.g., "SPT", "EDD").
51    fn name(&self) -> &'static str;
52
53    /// Evaluates the priority of a task given the current scheduling context.
54    ///
55    /// Returns a score where lower = higher priority.
56    fn evaluate(&self, task: &Task, context: &SchedulingContext) -> RuleScore;
57
58    /// Rule description.
59    fn description(&self) -> &'static str {
60        self.name()
61    }
62}