Skip to main content

ferrox/jobshop/
problem.rs

1use serde::{Deserialize, Serialize};
2
3/// One operation within a job: must execute on `machine_id` for `duration` units.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Operation {
6    pub machine_id: usize,
7    pub duration: i64,
8}
9
10/// A job is an ordered sequence of operations; each must complete before the next begins.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Job {
13    pub id: usize,
14    pub name: String,
15    /// Operations in their required execution order.
16    pub operations: Vec<Operation>,
17}
18
19/// Seeded into `ContextKey::Seeds` with id prefix `"jspbench-request:"`.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct JobShopRequest {
22    pub id: String,
23    pub jobs: Vec<Job>,
24    pub num_machines: usize,
25    #[serde(default = "default_time_limit")]
26    pub time_limit_seconds: f64,
27}
28
29fn default_time_limit() -> f64 {
30    30.0
31}
32
33impl JobShopRequest {
34    /// Trivial upper bound on makespan: sum of all operation durations.
35    pub fn horizon(&self) -> i64 {
36        self.jobs
37            .iter()
38            .flat_map(|j| j.operations.iter())
39            .map(|o| o.duration)
40            .sum()
41    }
42}
43
44/// A scheduled operation with resolved timing.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ScheduledOp {
47    pub job_id: usize,
48    pub job_name: String,
49    pub machine_id: usize,
50    pub op_index: usize,
51    pub start: i64,
52    pub end: i64,
53}
54
55/// Written to `ContextKey::Strategies` with id prefix `"jspbench-plan-<solver>:"`.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct JobShopPlan {
58    pub request_id: String,
59    pub schedule: Vec<ScheduledOp>,
60    pub makespan: i64,
61    /// Proven lower bound (available when status is `"optimal"`).
62    pub lower_bound: Option<i64>,
63    pub solver: String,
64    /// `"optimal"`, `"feasible"`, or `"error"`.
65    pub status: String,
66    pub wall_time_seconds: f64,
67}