Exercise for D-Wave in-person training course to demonstrate the CQM solver.
Run scheduling_preferences.py
. This program considers four employees
that need to be assigned to four open shifts. Each employee has a
ranking/preference amongst the four shifts according to the image below,
where 1 is most preferred and 4 is least preferred.
Read through the code and take a look at how we're building up our constrained quadratic model, or CQM. In particular, pay attention to:
- Initialize the CQM object with
cqm = ConstrainedQuadraticModel()
. - Create labels for binary variables for each employee in each shift.
- Create binary variable objects for each employee's shift.
- Add constraints over employee binaries for each employee with
cqm.add_constraint(...)
. - Add objective terms as linear biases based on the employee preferences with
cqm.objective.add_linear_from(...)
.
For this exercise, we'll work with the file scheduling_addemployees.py
.
This file is very similar to scheduling_preferences.py
, and you will be
adding additional employees to the schedule. Add the following employees
with their associated preferences for shifts 1-4 in the function employee_preferences()
.
- Erik: [1,3,2,4]
- Francis: [4,3,2,1]
- Greta: [2,1,4,3]
- Harry: [3,2,1,4]
When you run this problem, you should see two employees scheduled for each shift.
In this next exercise, we'll work with the file scheduling_restrictions.py
.
In this problem, we have 8 employees and 4 different shift options.
We've set up the initial CQM model for all 8 employees with their preferences
over the 4 shifts. Now we need to take into account the following restrictions.
- Anna is not able to work during shift 4.
- Bill and Frank cannot work during the same shift.
- Erica and Harriet would like to work the same shift.
Modify the function build_cqm()
to reflect these additional constraints.
Note that when you run your program, you may not have two employees per shift this time.
For this final exercise, start with your completed file scheduling_restrictions.py
from Exercise 2. The optimal solution for Exercise 2 had some days with just 1
person scheduled and others with many more. Add a constraint to your CQM so
that each shift gets exactly two people scheduled.
Released under the Apache License 2.0. See LICENSE file.