Overview
The autoscheduler uses a constraint-based search algorithm to find optimal placements for class sections. It considers teacher availability, room resources, grade requirements, and various other constraints while trying to maximize metrics like room utilization and student-class-hours.Core Components
AutoschedulerController
The main entry point for the autoscheduler system. Location:esp/esp/program/controllers/autoscheduler/controller.py
Initialization
constraints_*: Boolean flags for enabling/disabling constraints (e.g.,constraints_LunchConstraint=True)scorers_*: Weight values for scoring functions (e.g.,scorers_NumSectionsScorer=100.0)resources_*: Resource criterion weights, or -1 for required constraintssearch_*: Search configuration parameters
Key Methods
compute_assignments()
Runs the optimization algorithm to find class placements.
get_scheduling_info()
Returns human-readable information about what changed.
export_assignments() and import_assignments(data)
Save and restore scheduling decisions.
save_assignments()
Persists the computed schedule to the database.
Static Configuration Methods
constraint_options(prog)
Returns available constraints with descriptions.
scorer_options(prog)
Returns available scorers with their weights.
resource_options(prog)
Returns resource criteria configuration.
search_options(prog, section=None)
Returns search configuration options.
Data Model
The autoscheduler uses in-memory data structures for performance. Location:esp/esp/program/controllers/autoscheduler/data_model.py
AS_Schedule
Represents a complete program schedule.program: Program objecttimeslots: List of AS_Timeslot objectsclass_sections: Dict of{section_id: AS_ClassSection}teachers: Dict of{teacher_id: AS_Teacher}classrooms: Dict of{classroom_name: AS_Classroom}lunch_timeslots: Dict mapping days to lunch timeslot listsconstraints: CompositeConstraint object
AS_ClassSection
Represents a class section to be scheduled. Attributes:id: Section IDparent_class: Parent class IDduration: Duration in hoursteachers: List of AS_Teacher objectscapacity: Maximum student capacitygrade_min,grade_max: Grade rangecategory: Category IDassigned_roomslots: Sorted list of assigned AS_RoomSlot objectsresource_requests: Dict of requested resources
AS_Classroom
Represents a classroom with availability. Key Method:AS_Teacher
Attributes:id: Teacher IDavailability: List of available timeslotstaught_sections: Dict of sections being taughtis_admin: Whether teacher is an adminavailability_dict: Fast lookup of (start, end) tuples
Constraints
Constraints define what schedules are legal. Location:esp/esp/program/controllers/autoscheduler/constraints.py
Required Constraints
These are always enforced:- ContiguousConstraint: Multi-hour sections must be in contiguous timeblocks in the same room
- PreconditionConstraint: Only unschedule already-scheduled classes, etc.
- RoomAvailabilityConstraint: Only use reserved rooms
- RoomConcurrencyConstraint: No double-booking rooms
- SectionDurationConstraint: Sections scheduled for exact duration
- TeacherAvailabilityConstraint: Teachers only teach when available
- TeacherConcurrencyConstraint: Teachers can’t teach two classes at once
Optional Constraints
- LunchConstraint: Don’t schedule multi-hour sections over both lunch blocks
- ResourceCriteriaConstraint: Enforce custom resource criteria
Configuration
Constraints can be enabled via tags or user input:Scoring
Scorers evaluate schedule quality (higher is better). Location:esp/esp/program/controllers/autoscheduler/scoring.py
Available Scorers
| Scorer | Default Weight | Description |
|---|---|---|
| NumSectionsScorer | 100.0 | Schedule as many sections as possible |
| ResourceMatchingScorer | 500.0 | Match requested resources |
| ResourceValueMatchingScorer | 450.0 | Match requested resource values |
| RoomSizeMismatchScorer | 350.0 | Use appropriately sized rooms |
| ResourceCriteriaScorer | 300.0 | Score custom resource criteria |
| AdminDistributionScorer | 70.0 | Distribute admin classes evenly, not in morning |
| HungryTeacherScorer | 70.0 | Avoid teachers teaching both lunch blocks |
| NumSubjectsScorer | 60.0 | Schedule distinct classes |
| NumTeachersScorer | 50.0 | Schedule distinct teachers |
| StudentClassHoursScorer | 50.0 | Maximize student-class-hours |
| LunchStudentClassHoursScorer | 20.0 | Prioritize non-lunch scheduling |
| CategoryBalanceScorer | 10.0 | Balance categories evenly |
| RoomConsecutivityScorer | 10.0 | Schedule classes consecutively in rooms |
| TeachersWhoLikeRunningScorer | 10.0 | Avoid back-to-back in different rooms |
Configuration
Resource Criteria
Custom resource matching rules can be defined. Location:esp/esp/program/controllers/autoscheduler/config.py
Constraint Example
Scoring Example
Search Algorithm
The search uses depth-limited DFS to find improvements. Location:esp/esp/program/controllers/autoscheduler/search.py
SearchOptimizer
- Try all possible room slots for the target section
- If a slot is occupied, recursively try to move the conflicting section (up to depth)
- Evaluate the score after each complete assignment
- Keep the best solution found
- Depth 1: Only schedule into empty slots
- Depth 2: Can move one blocking section
- Depth 3: Can move chains of 2 sections (slow)
- Depth 4+: Too slow for practical use
Configuration
Location:esp/esp/program/controllers/autoscheduler/config.py
Key Constants
Tag-based Configuration
Program-specific overrides use Django tags:autoscheduler_constraint_overrides: JSON dict of constraint overridesautoscheduler_scorer_weight_overrides: JSON dict of scorer weightsautoscheduler_resource_constraint_overrides: JSON dict of resource constraintsautoscheduler_resource_scoring_overrides: JSON dict of resource scoring
Usage Example
Database Integration
The autoscheduler loads data from and saves back to Django models. Location:esp/esp/program/controllers/autoscheduler/db_interface.py
Loading
Saving
ClassSection meeting times in the database based on the in-memory schedule.
Error Handling
The autoscheduler defines custom exceptions: Location:esp/esp/program/controllers/autoscheduler/exceptions.py
Performance Considerations
- The autoscheduler loads the entire program schedule into memory
- Search depth 3+ can be very slow for large programs
- Use
USE_TIMER = Truein config to profile performance - Resource matching is one of the most expensive operations
- Consider limiting the number of sections to optimize at once
See Also
- Lottery Controller - For lottery-based student assignment
- Program models in
esp/esp/program/models - Resource models in
esp/esp/resources/models