This repository explores a programmatic solution for assigning lecture courses to time slots, specifically tailored to the scheduling regulations adopted by Harvard’s Faculty of Arts and Sciences (FAS) starting in Fall 2018. The code implements a combinatorial optimization approach to ensure fairness, compliance with institutional constraints, and maximization of faculty satisfaction.
Harvard’s FAS scheduling rules require that:
- Courses meeting more than once per week shall be scheduled in the Monday-Wednesday-Friday (MWF) sequence or the Tuesday-Thursday (TT) sequence.
- No class shall start at a time other than the designated class start times.
- Each department must ensure that courses are balanced between MWF and TT sequences, with no more than a two-course difference between them.
- Each department must ensure the difference between the most and least used start times must not exceed two courses.
- Members of the voting faculty are not allowed to teach Tuesdays from 3:00pm to 5:00pm as that would conflict with FAS faculty meetings.
In addition, the Department of History will seek to accommodate faculty preferences to the greatest extent possible. This will be accomplished by polling faculty members about their preferences ahead of each semester. In the poll, faculty will be asked to rank their slot preferences for each course.
It is unlikely that all of their first preferences could be accommodated while also fulfilling the new regulations. Finding the best solution can be formulated as a combinatorial optimisation problem, specifically a variant of the generalized assignment problem. The goal is to assign each course to a time slot such that all constraints are satisfied and faculty preferences are considered to the maximum extent possible.
Let
For slot popularity, we use Kendall's Tau distance to find the Kemeny-Young consensus ranking that minimizes disagreement across all faculty preferences.
The satisfaction score
where
The solution, as implemented in scheduling.ipynb follows these steps:
-
1. Data ingestion: Load faculty preferences, course-faculty mappings, and faculty metadata from CSV files.
-
2. Slot definition: Define 10 time slots (9:00-15:00) grouped by day pattern (MWF/TT) and start time.
-
3. Slot popularity calculation: Use Kemeny-Young consensus ranking to determine slot popularity from faculty preferences.
-
4. Satisfaction matrix construction: For each course-slot pair, compute satisfaction using:
- Base satisfaction:
$(5 - p_{c,t})$ where$p_{c,t}$ is preference rank - Popularity penalty: subtract slot popularity score derived from Kemeny-Young consensus
- Tie-breaking: add random value
$\epsilon \sim \text{Uniform}(0.1, 1.0)$ - Clamp to non-negative values:
$s_{c,t} = \max(0, \text{base} - \text{penalty} + \epsilon)$
- Base satisfaction:
-
5. MIP solver: Use Google OR-Tools Coin-or branch and cut (CBC) mixed integer programming solver to maximize total satisfaction. The absolute value and min/max constraints in the mathematical formulation are linearized using standard MIP techniques:
- Absolute value constraint
$|A - B| \leq 2$ becomes:$A - B \leq 2 \text{ and } B - A \leq 2$ - Min/max constraint becomes individual constraints for each start time:
$\sum_{t \in T_k} \sum_{c \in C} x_{c,t} \geq \text{stime-min} \text{ and } \sum_{t \in T_k} \sum_{c \in C} x_{c,t} \leq \text{stime-max}$
- Absolute value constraint
-
6. Solution extraction and visualization: Output assignment matrix and verify constraint satisfaction.
scheduling.ipynb generates comprehensive visualizations to analyze the optimization results:
- Slot Usage Chart: Shows courses per time slot, color-coded by MWF/TT pattern
- Day Pattern Distribution: Pie chart showing MWF vs TT balance
- Start Time Distribution: Bar chart showing course distribution across start times
- Satisfaction Score Histogram: Distribution of satisfaction scores across all assignments
- Popularity vs Usage Scatter Plot: Relationship between slot popularity and actual usage
- Balance Verification: Visual confirmation of MWF/TT and start time balance constraints
- Assignment Heatmap: Visual representation of the final course-slot assignment matrix
- Summary Metrics: Key performance indicators including total satisfaction, constraint compliance, and solve time
Anonymized sample data is included in the data directory:
- selections.csv: Faculty preference matrix (courses × time slots) with rankings 1-10 where 1 = most preferred, 10 = least preferred. Value 0 indicates the faculty member is unavailable in that slot.
- courses.csv: Course-faculty mapping with columns: Course, Faculty
- faculty.csv: Faculty metadata with columns: Faculty, Adjustment, Voting (1=voting faculty, 0=non-voting)
The sample dataset contains 45 courses taught by 18 faculty members across 10 time slots.
A complete web-based implementation is provided as a Dash application:
-
Install dependencies:
pip install -r requirements.txt
-
Start the application:
python ./app/app.py
-
Load data files:
- Upload faculty data (faculty.csv)
- Upload course-faculty mapping (courses.csv)
- Upload preference selections (selections.csv)
-
Run optimization:
- Click "Calculate" to run the scheduling optimization
- View results, constraint compliance, and visualizations
The app will be available at http://127.0.0.1:8050 in your browser.
The project is licensed under the MIT License, allowing free use, modification, and distribution.



