A constraint solver for generating schedules
Project description
Course Constraint Scheduler
A powerful constraint satisfaction solver for generating academic course schedules using the Z3 theorem prover.
Overview
The Course Constraint Scheduler is designed to solve complex academic scheduling problems by modeling them as constraint satisfaction problems. It can handle:
- Faculty Constraints: Availability, credit limits, course preferences
- Room Constraints: Room assignments, lab requirements, capacity limits
- Time Constraints: Time slot conflicts, meeting patterns, duration requirements
- Course Constraints: Prerequisites, conflicts, section limits
- Optimization: Multiple optimization strategies for better schedules
Features
- Z3 Integration: Uses Microsoft's Z3 theorem prover for efficient constraint solving
- Flexible Configuration: JSON-based configuration for easy customization
- Multiple Output Formats: JSON and CSV output support
- REST API: Full HTTP API for integration with web applications
- Asynchronous Processing: Background schedule generation for large problems
- Session Management: Persistent sessions for iterative schedule generation
- Optimization Flags: Configurable optimization strategies
Quick Start
Requires a minimum version of Python 3.12
Installation
pip install course-constraint-scheduler
Command Line Usage
# Generate schedules from configuration file
scheduler config.json --limit 10 --format json --output schedules
# Interactive mode
scheduler config.json --limit 5
Python API
from scheduler import Scheduler, load_config_from_file
# Load configuration
config = load_config_from_file("config.json")
# Create scheduler
scheduler = Scheduler(config)
# Generate schedules
for schedule in scheduler.get_models():
print(f"Generated schedule: {schedule}")
REST API
# Start the server
scheduler-server --port 8000
# Submit a schedule request
curl -X POST "http://localhost:8000/submit" \
-H "Content-Type: application/json" \
-d @example.json
Documentation
- Python API Documentation - Complete Python API reference
- REST API Documentation - Full REST API specification
- Configuration Guide - Configuration file format and examples
Configuration
The scheduler uses a JSON configuration file that defines:
- Rooms and Labs: Available facilities and their constraints
- Courses: Course requirements, conflicts, and faculty assignments
- Faculty: Availability, preferences, and teaching constraints
- Time Slots: Available time blocks and class patterns
- Optimization: Flags for different optimization strategies
Example configuration:
{
"config": {
"rooms": ["Room A", "Room B"],
"labs": ["Lab 1"],
"courses": [
{
"course_id": "CS101",
"credits": 3,
"room": ["Room A"],
"lab": ["Lab 1"],
"conflicts": [],
"faculty": ["Dr. Smith"]
}
],
"faculty": [
{
"name": "Dr. Smith",
"maximum_credits": 12,
"minimum_credits": 6,
"unique_course_limit": 3,
"times": {
"MON": ["09:00-17:00"],
"TUE": ["09:00-17:00"],
"WED": ["09:00-17:00"],
"THU": ["09:00-17:00"],
"FRI": ["09:00-17:00"]
}
}
]
},
"time_slot_config": {
"times": {
"MON": [
{
"start": "09:00",
"spacing": 60,
"end": "17:00"
}
]
},
"classes": [
{
"credits": 3,
"meetings": [
{
"day": "MON",
"duration": 150,
"lab": false
}
]
}
]
},
"limit": 10,
"optimizer_flags": ["faculty_course", "pack_rooms"]
}
Architecture
The scheduler is built with a modular architecture:
- Core Solver: Z3-based constraint satisfaction engine
- Configuration Management: Pydantic-based configuration validation
- Model Classes: Data structures for courses, faculty, and time slots
- Output Writers: JSON and CSV output formatters
- REST Server: FastAPI-based HTTP API
- Session Management: Persistent session handling for large problems
Performance
- Small Problems (< 10 courses): Near-instantaneous solving
- Medium Problems (10-50 courses): Seconds to minutes
- Large Problems (50+ courses): May take several minutes
- Optimization: Use appropriate optimizer flags to reduce solving time
Development
Setup
# Clone the repository
git clone <repository-url>
cd course-constraint-scheduler
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check src/
Project Structure
src/scheduler/
├── __init__.py # Main package exports
├── config.py # Configuration models
├── main.py # Command-line interface
├── scheduler.py # Core scheduling logic
├── server.py # REST API server
├── models/ # Data models
│ ├── course.py # Course and instance models
│ ├── day.py # Day enumeration
│ ├── time_slot.py # Time-related models
│ └── identifiable.py # Base identifiable class
├── writers/ # Output formatters
│ ├── json_writer.py # JSON output
│ └── csv_writer.py # CSV output
└── logging.py # Logging configuration
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions, issues, or feature requests:
- Check the documentation
- Review existing issues
- Create a new issue with detailed information
- Include configuration examples and error messages
Roadmap
- Web-based configuration interface
- Schedule visualization tools
- Multi-objective optimization support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file course_constraint_scheduler-2.0.0.tar.gz.
File metadata
- Download URL: course_constraint_scheduler-2.0.0.tar.gz
- Upload date:
- Size: 89.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32ac2ff6517a2648132c47f3aed535355c1df1c2b7ffb97d729545042e6c6f8c
|
|
| MD5 |
9997a3d72a55b0489d7d5d36b66b097e
|
|
| BLAKE2b-256 |
ccfa755a955c06d1793a49bc55adc25e32063513a97facef63ce6b4a223a99d8
|
File details
Details for the file course_constraint_scheduler-2.0.0-py3-none-any.whl.
File metadata
- Download URL: course_constraint_scheduler-2.0.0-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6f826c2a40eb645107c863426f98d7cdcf554b14eb0e1d95faacea383a2e27e
|
|
| MD5 |
f315d7e63c6945d9b254233dee33eae2
|
|
| BLAKE2b-256 |
9895aaadafe8de786bfc8b441a55069cbea01905c56265024ac3fab3fe35c4d6
|