Solution for the Lab 2 class example: scheduling auto repair jobs with the Z3 constraint solver. It covers all of the requirements and both options in Challenge 2. It doesn’t include Challenge 1.
| File | What it does |
|---|---|
data_loader.py |
Loads the CSV files into lists of dictionaries |
scheduler.py |
The Z3 model, solving, the unsat core, and Challenge 2 |
main.py |
Prints the schedule, the unsolvable data reports, and Challenge 2 results |
test_scheduler.py |
A plain Python schedule checker and the tests |
../Data/ |
The data files from the lab instructions (mechanics.csv, bays.csv and jobs.csv). They are in the Data folder next to this folder, not in this one. |
../Data/unsolvable_data/ |
Three data sets that each break a different rule |
Run the program and the tests from this folder. The code opens files using relative paths (../Data and ../Data/unsolvable_data), and Python starts those paths at the folder where the code is running, not the folder that holds the .py file. If you run it from somewhere else, it won’t find the data.
uv run main.py
uv run test_scheduler.py
uv run pytest # the same tests, run with pytest
Note: If you are not familiar with pytest, you don’t need to use it in your actual lab assigment. If you do know how to use pytest you are welcome to use it instead of the test drivers.
| Folder | What was changed | Expected group in the core |
|---|---|---|
uncertified_service |
Job J122 is a diesel job, and no mechanic is certified for diesel |
qualification |
reversed_time_window |
Job J105 has earliest_slot 5 and latest_slot 3 |
time_window |
too_many_jobs |
Only Fatima Noor (part-time, max 2) is certified for air_conditioning, which 3 jobs need |
workload |
Keep a workload conflict small. In testing, a version with 14 jobs for 13 openings timed out instead of proving it was unsat.
push()/pop() loop) lowers the limit by 1 each time, as in the lab instructions, and stops at the lower bound.Optimize) turns the constraint groups on by adding the flags as constraints. Passing them to check() as assumptions made the optimizer time out in testing.