I’m starting to learn ortools.sat.python
/ cp_model
and I am confused as how to use model.minimize()/maximize()
.
Let’s take an example simple problem of booking meetings to timeslots and rooms:
model = cp_model.CpModel()
bookings = {}
for m in meetings:
for t in timeslots:
for r in rooms:
bookings[(m, t, r)] = model.new_bool_var(f"{m}_{t}_{r}")
# 1. each meeting shall be held once
for m in meetings:
model.add_exactly_one(bookings[(m, t, r)] for r in rooms for t in timeslots)
# 2. no overbooking: no two meetings can be booked for the same timeslot-room pair
for t in timeslots:
for r in rooms:
model.add_at_most_one(bookings[(m, t, r)] for m in meetings)
Now, what I would like to further improve, is to minimize the total number of uniquely booked rooms. In other words, if it is possible to create the whole booking schedule using e.g. 3 unique rooms only (and not all 5 or 6 or whatever), then such solution should be preferred.
How do I do that?