Skip to content

Commit 3ce640a

Browse files
committed
docs: update to the latest version of the Python quickstart
1 parent 30980b7 commit 3ce640a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

docs/src/modules/ROOT/pages/quickstart/hello-world/hello-world-quickstart.adoc

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,19 @@ from datetime import time
624624
import logging
625625
import 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
630630
logging.config.fileConfig('logging.conf')
631631
LOGGER = logging.getLogger('app')
632632

633-
634633
def 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

660659
def 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

702704
def 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
----
11071111
from 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
11101112
from datetime import time
11111113

1114+
from hello_world.domain import *
1115+
from hello_world.constraints import *
1116+
11121117
ROOM1 = Room("Room1")
1118+
ROOM2 = Room("Room2")
11131119
TIMESLOT1 = Timeslot("MONDAY", time(12, 0), time(13, 0))
11141120
TIMESLOT2 = 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

11181126
def test_room_conflict():
11191127
first_lesson = Lesson("1", "Subject1", "Teacher1", "Group1", TIMESLOT1, ROOM1)

docs/src/modules/ROOT/pages/quickstart/school-timetabling/school-timetabling-constraints.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,9 @@ from timefold.solver.score import (constraint_provider, HardSoftScore, Joiners,
357357
ConstraintFactory, Constraint)
358358
from .domain import Lesson
359359
360-
361360
@constraint_provider
362-
def school_timetabling_constraints(constraint_factory: ConstraintFactory):
361+
def define_constraints(constraint_factory: ConstraintFactory):
363362
return [
364-
# Hard constraints
365363
room_conflict(constraint_factory),
366364
teacher_conflict(constraint_factory),
367365
student_group_conflict(constraint_factory),

0 commit comments

Comments
 (0)