@@ -624,20 +624,19 @@ from datetime import time
624624import logging
625625import logging.config
626626
627- from .domain import Lesson, Timeslot, Room, Timetable
628- from .constraints import school_timetabling_constraints
627+ from .domain import *
628+ from .constraints import define_constraints
629629
630630logging.config.fileConfig('logging.conf' )
631631LOGGER = logging.getLogger('app' )
632632
633-
634633def main():
635634 solver_factory = SolverFactory.create(
636635 SolverConfig(
637636 solution_class=Timetable,
638637 entity_class_list=[Lesson],
639638 score_director_factory_config=ScoreDirectorFactoryConfig(
640- constraint_provider_function=school_timetabling_constraints
639+ constraint_provider_function=define_constraints
641640 ),
642641 termination_config=TerminationConfig(
643642 # The solver runs only for 5 seconds on this small dataset.
@@ -658,12 +657,15 @@ def main():
658657
659658
660659def generate_demo_data() -> Timetable:
660+ days = ('MONDAY', 'TUESDAY')
661661 timeslots = [
662662 Timeslot(day, start, start.replace(hour=start.hour + 1))
663- for day in ('MONDAY', 'TUESDAY')
663+ for day in days
664664 for start in (time(8, 30), time(9, 30), time(10, 30), time(13, 30), time(14, 30))
665665 ]
666- rooms = [Room(f'Room {name}') for name in ('A', 'B', 'C')]
666+
667+ room_ids = ('A', 'B', 'C')
668+ rooms = [Room(f'Room {name}') for name in room_ids]
667669
668670 lessons = []
669671
@@ -701,6 +703,8 @@ def generate_demo_data() -> Timetable:
701703
702704def print_timetable(time_table: Timetable) -> None:
703705 LOGGER.info("")
706+
707+ column_width = 18
704708 rooms = time_table.rooms
705709 timeslots = time_table.timeslots
706710 lessons = time_table.lessons
@@ -709,8 +713,8 @@ def print_timetable(time_table: Timetable) -> None:
709713 for lesson in lessons
710714 if lesson.room is not None and lesson.timeslot is not None
711715 }
712- row_format ="|{:<15}" * (len(rooms) + 1) + "|"
713- sep_format = "+" + ((("-" * 15 ) + "+") * (len(rooms) + 1))
716+ row_format = ( "|{:<" + str(column_width) + "}") * (len(rooms) + 1) + "|"
717+ sep_format = "+" + ((("-" * column_width ) + "+") * (len(rooms) + 1))
714718
715719 LOGGER.info(sep_format)
716720 LOGGER.info(row_format.format('', *[room.name for room in rooms]))
@@ -789,7 +793,7 @@ solver_factory = SolverFactory.create(
789793 solution_class=Timetable,
790794 entity_class_list=[Lesson],
791795 score_director_factory_config=ScoreDirectorFactoryConfig(
792- constraint_provider_function=school_timetabling_constraints
796+ constraint_provider_function=define_constraints
793797 ),
794798 termination_config=TerminationConfig(
795799 # The solver runs only for 5 seconds on this small dataset.
@@ -1105,15 +1109,19 @@ Create the `tests/test_constraints.py` file with the following contents:
11051109[source,python]
11061110----
11071111from timefold.solver.test import ConstraintVerifier
1108- from hello_world.domain import Timetable, Lesson, Room, Timeslot
1109- from hello_world.constraints import school_timetabling_constraints, room_conflict
11101112from datetime import time
11111113
1114+ from hello_world.domain import *
1115+ from hello_world.constraints import *
1116+
11121117ROOM1 = Room("Room1")
1118+ ROOM2 = Room("Room2")
11131119TIMESLOT1 = Timeslot("MONDAY", time(12, 0), time(13, 0))
11141120TIMESLOT2 = Timeslot("TUESDAY", time(12, 0), time(13, 0))
1121+ TIMESLOT3 = Timeslot("TUESDAY", time(13, 0), time(14, 0))
1122+ TIMESLOT4 = Timeslot("TUESDAY", time(15, 0), time(16, 0))
11151123
1116- constraint_verifier = ConstraintVerifier.build(school_timetabling_constraints , Timetable, Lesson)
1124+ constraint_verifier = ConstraintVerifier.build(define_constraints , Timetable, Lesson)
11171125
11181126def test_room_conflict():
11191127 first_lesson = Lesson("1", "Subject1", "Teacher1", "Group1", TIMESLOT1, ROOM1)
0 commit comments