Commit aedc1c80 authored by Thomas Stone's avatar Thomas Stone
Browse files

testing

parent 3cea0625
from ortools.sat.python import cp_model
from schedule_objects import Course, Room, Professor
def simple_schedule():
# Creates the model.
model = cp_model.CpModel()
# Simple variables
simple_classes = ['class1', 'class2', 'class3', 'class4', 'class5', 'class6', 'class7']
simple_classes_size = [20, 20, 20, 20, 20, 20, 20]
# Requirements: 0=Chairs, 1=Tables, 2=Computers
simple_classes_requirements = [0, 0, 1, 1, 2, 2, 0]
simple_class_lengths = [1, 1, 1, 1, 1, 1, 1]
simple_classes = ['class1-01', 'class1-02', 'class2-01', 'class2-02', 'class2-03', 'class3', 'class4']
#simple_classes_size = [20, 20, 20, 20, 20, 20, 20]
simple_times = ['08', '09', '10', '11', '12', '13', '14', '15', '16']
simple_rooms_features = [0, 1, 2]
simple_rooms = ['room0', 'room1', 'room2']
simple_rooms_capacity = [30, 40, 50]
#simple_rooms_capacity = [30, 40, 50]
simple_profs = ['prof1', 'prof2', 'prof3', 'prof4']
simple_profs_load = [3, 3, 3, 3]
simple_prof_teachable = [['class1', 'class2', 'class3', 'class4'],
['class3', 'class4', 'class5', 'class6'],
['class6', 'class7'],
['class1', 'class4', 'class5']
]
#simple_profs = ['prof1', 'prof2', 'prof3', 'prof4']
# simple_prof_teachable = [['class1', 'class2', 'class3', 'class4'],
# ['class3', 'class4', 'class5', 'class6'],
# ['class6', 'class7'],
# ['class1', 'class4', 'class5']
# ]
profs = []
courses = []
rooms = []
for name, size, req, length in zip(simple_classes, simple_classes_size, simple_classes_requirements,
simple_class_lengths):
courses.append(Course(name, size, req, length))
# for name, size, req, length in zip(simple_classes, simple_classes_size, simple_classes_requirements,
# simple_class_lengths):
# courses.append(Course(name, size, req, length))
for room, capacity, feature in zip(simple_rooms, simple_rooms_capacity, simple_rooms_features):
rooms.append(Room(room, capacity, feature))
# for room, capacity, feature in zip(simple_rooms, simple_rooms_capacity, simple_rooms_features):
# rooms.append(Room(room, capacity, feature))
for prof, load, teachable in zip(simple_profs, simple_profs_load, simple_prof_teachable):
profs.append(Professor(prof, load, teachable))
# for prof, load, teachable in zip(simple_profs, simple_profs_load, simple_prof_teachable):
# profs.append(Professor(prof, load, teachable))
# Array to store all variables
scheduled_classes = {}
for n in courses:
for n in simple_classes:
for t in simple_times:
for c in rooms:
for c in simple_rooms:
scheduled_classes[(n, t, c)] = model.NewBoolVar(f'{n}_{t}_{c}')
# Add Constraints
......@@ -53,26 +45,22 @@ def simple_schedule():
for n in courses:
num_classes_taught = 0
for t in simple_times:
for c in rooms:
for c in simple_rooms:
num_classes_taught += scheduled_classes[(n, t, c)]
model.Add(num_classes_taught == 1)
# Each class must only be taught in one room at a time
for c in rooms:
for c in simple_rooms:
for t in simple_times:
model.Add(sum(scheduled_classes[(n, t, c)] for n in courses) <= 1)
# Each class can only go in a room that fits its type and a room that has enough seats
for n in courses:
for c in rooms:
for c in simple_rooms:
if n.room_requirement != c.features or n.size > c.capacity:
model.Add(sum(scheduled_classes[(n, t, c)] for t in simple_times) == 0)
for p in profs:
for possible_class in p.teachable_classes:
model.Add()
# Hardcode constraint that class1 is taught at 14
# model.Add(scheduled_classes[(courses[0],'14',rooms[0])] == 1)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment