A Python automation tool solving the “Term Master Schedule” problem (and used throughout my undergrad from 2016 to 2020).

Overview

Manually creating a university schedule involves solving a Constraint Satisfaction Problem (CSP) with multiple variables:

  • Hard Constraints: No time overlaps between classes.
  • Soft Constraints: Preferences for “no 8 AMs,” specific lunch breaks, or maximizing free days.

The naive approach (manually checking every possible combination) becomes intractable as the number of courses and sections grows.

Features

I built a script that:

  1. Scraped Data: Parsed the Drexel WebTMS (Term Master Schedule) using lxml to build a localized dataset of course availability.
  2. Solved for X: Implemented a recursive backtracking algorithm to generate every valid schedule permutation that satisfied user-defined constraints.

The Algorithm

The core of this project is a recursive_generator function that implements a valid CSP solver using backtracking. It performs a recursive depth-first search that:

  1. Takes a set of variables (courses).
  2. Checks constraints (time overlaps, lunch hours, max classes per day).
  3. Backtracks when a branch fails.

It is the same backtracking pattern used in everything from Sudoku solvers to compiler register allocation.

Usage

The tool is run via the command line, taking a list of desired courses and outputting valid schedule combinations.

Retrospective

The scraping logic was tied to 2017 HTML and has since rotted. The durable part is the search itself: a depth-first walk of the schedule state space with constraint pruning.