I asked few days ago, a question about how to transform a University Class Scheduling Problem into a Boolean Satisfiability Problem.
(Class Scheduling to Boolean sa
This answer is extension of Part 1's answer, and uses the same notations when possible.
Ok, assume each interval is assigned to one teacher (if more than one teacher can take the interval, just have multiple instances of it, with different teachers per instance), so to indicate teacher t
teaches in a classroom p
at time x
to y
, we can use the old variable that this class is given - V_{i,j}
- for the class and interval.
For each teacher t
, and for each pair of intervals c=(x1,y1)
, d=(x2,y2)
in classes (a,b) the teacher might participate in, add the clause:
Q_{t,i,j} = Not(V_ac) OR Not(V_bd) OR Smaller(y1,x2) OR Smaller(y2,x1)
Intuitively, the above clause guarantees a teacher cannot be in the same time in two places - no intervals overlap that the same teacher is assigned to them.
By chaining each pair (i,j)
for each teacher t
with AND to the original formula, it satisfies your first constraint - a teacher cannot be in 2 places in the same interval.
- since each teacher cannot be in two places at the same time.
Your second constraint there cannot be 2 teachers in the same room for the same interval.
is also satisfied by the fact that there cannot be two classes that overlap the time and class.
The 3rd constraint there is a least 1 interval true by course.
is satisfied by the F1
clause, since you have to choose at least one interval (with one teacher assigned) for each course.