Ich habe ein kleines Skript erstellt, um herumzuspielen und zu lernen, wie man oder Tools verwendet. /> Lehrer können ihre maximal zugewiesenen wöchentlichen Stunden nicht überschreiten. < /li>
Die maximale Anzahl von Stunden pro Tag für jedes Thema und die Gruppe ist begrenzt. Lehrer und zwei Gruppen (1-A und 1-B). https://github.com/ehdez73/school-timet ... metable.py
model = cp_model.CpModel()
# Create decision variables (group-subject-teacher-day-hour)
assignments = {}
for group in all_groups:
course = group.split('-')[0]
for subject in all_subjects:
if subject.course == course:
for teacher in all_teachers:
if subject in teacher.subjects:
for d in range(num_days):
for h in range(num_hours):
key = (group, subject.id, teacher.id, d, h)
assignments[key] = model.NewBoolVar(f"g:{group} sub:{subject.id} t:{teacher.name} d:{d} h:{h}")
# Each subject must be taught the specified weekly hours
for group in all_groups:
course = group.split('-')[0]
for subject in all_subjects:
if subject.course == course:
model.Add(sum(assignments[key] for key in assignments if key[0] == group and key[1] == subject.id) == subject.weekly_hours)
# A teacher cannot teach two classes at the same time
for teacher in all_teachers:
for d in range(num_days):
for h in range(num_hours):
model.AddAtMostOne(assignments[key] for key in assignments if key[2] == teacher.id and key[3] == d and key[4] == h)
# Teachers cannot exceed their maximum assigned weekly hours.
for teacher in all_teachers:
max_hours = teacher.max_hours_week
teacher_total_hours = sum(assignments[key] for key in assignments if key[2] == teacher.id)
model.Add(teacher_total_hours
Schedule for 1-A
Hour | Mon | Tue | Wed | Thu | Fri
-------+--------------+--------------+--------------+--------------+-------------
Hour 0 | Maths (John) | - | - | Maths (John) | -
Hour 1 | - | - | - | - | -
Hour 2 | - | Maths (John) | Maths (John) | Maths (John) | Maths (John)
Hour 3 | Maths (John) | Maths (John) | - | - | Maths (John)
Hour 4 | - | - | Maths (John) | - | -
Schedule for 1-B
Hour | Mon | Tue | Wed | Thu | Fri
-------+--------------+--------------+--------------+--------------+-------------
Hour 0 | - | Maths (John) | Maths (John) | - | Maths (John)
Hour 1 | Maths (John) | - | - | Maths (John) | Maths (John)
Hour 2 | - | - | - | - | -
Hour 3 | - | - | Maths (John) | - | -
Hour 4 | Maths (John) | Maths (John) | - | Maths (John) | -
< /code>
Any idea why it is not working ?
Wie kann ich aufeinanderfolgende Stunden für den Schulzeitplan in Google oder-Tools CP-SAT durchsetzen? ⇐ Python
-
- Similar Topics
- Replies
- Views
- Last post
Mobile version