Spaces:
Running
Running
Core Module — Domain and Scheduling Algorithm
Directory: scheduler/core/
This package defines the domain objects (cases, hearings, courtrooms, judges), the ripeness classifier, policy interfaces, and the main scheduling algorithm that orchestrates daily scheduling.
Files overview
algorithm.py- Purpose: Implements the daily scheduling pipeline.
- Key classes:
SchedulingResult: Aggregates scheduled cases, unscheduled reasons, applied overrides, and explanations.SchedulingAlgorithm: Orchestrates the day’s scheduling.schedule_day(cases, courtrooms, current_date, overrides, preferences, max_explanations_unscheduled)- Flow:
- Compute judge preference overrides (if provided).
- Filter by ripeness (via
RipenessClassifier), tracking unscheduled reasons for unripe cases. - Filter eligibility (age gaps, disposed, same‑day constraints) and compute priority.
- Apply manual overrides (add/remove cases; capacity changes).
- Allocate cases to courtrooms (via allocator interface used in simulation layer).
- Generate explanations for unscheduled cases (up to cap) and successful allocations.
- Inputs: list of
Case, list ofCourtroom,date, optionalOverridelist, optionalJudgePreferences. - Outputs:
SchedulingResultwith scheduled list and explanations.
- Flow:
- Internal helpers:
_filter_by_ripeness,_filter_eligible,_get_preference_overrides,_apply_manual_overrides,_allocate_cases,_clear_temporary_case_flags.
- Interactions:
core.ripeness,control.overrides,simulation.allocator.
case.py- Purpose: Core case model and priority logic.
- Key classes:
CaseStatus: Enum of lifecycle statuses.Case: Fields describe type, stage, history, last hearing, etc.- Selected methods:
progress_to_stage,record_hearing,update_age,compute_readiness_score,is_ready_for_scheduling,needs_alert,get_priority_score,mark_unripe,mark_ripe,mark_scheduled,is_disposed,to_dict.
- Selected methods:
- Interactions: Used by ripeness classifier, scheduler, and simulation.
courtroom.py- Purpose: Represents courtroom capacity and scheduling slots.
- Typical members: courtroom identifier, capacity/availability for a given
date. - Interactions: Allocator consumes courtroom capacity when placing cases.
hearing.py- Purpose: Hearing record representation (date, outcome, adjournment, etc.).
- Interactions: Case history and scheduler eligibility checks (min gap, outcomes).
judge.py- Purpose: Judge metadata and optional preference hooks.
- Interactions:
control.overrides.JudgePreferencesintegrates with algorithm preference overrides.
policy.py- Purpose: Defines the scheduling policy interface and default implementations for prioritization heuristics.
- Interactions: Injected into
SchedulingAlgorithmto determine case ordering.
ripeness.py- Purpose: Ripeness classifier and thresholds.
- Key elements:
RipenessStatusenum with helpersis_ripe()andis_unripe().RipenessClassifierwith methods:classify(case, current_date): returnsRipenessStatusand sets reasons.get_ripeness_priority(case, current_date): numeric priority for scheduling.is_schedulable(case, current_date): boolean gate for eligibility.get_ripeness_reason(status): human‑readable reason strings.estimate_ripening_time(case, current_date): expected time until ready.set_thresholds(new_thresholds),get_current_thresholds().
- Interactions: Used both by
algorithm.pyand the simulation engine.
Core flow (within SchedulingAlgorithm.schedule_day)
- Collect inputs (cases, courtrooms, date, optional overrides/preferences).
- Ripeness filter: mark unripe with reasons; compute ripeness‑based priority.
- Eligibility filter: ensure min gap since last hearing, exclude disposed, enforce capacity constraints.
- Apply overrides (manual changes and judge preferences).
- Allocate to courtrooms; finalize schedule.
- Produce explanations and a
SchedulingResult.