Created
May 19, 2016 03:20
-
-
Save sahuguet/44e0bb3348d84e692efa483079d033b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We define our solver. | |
solver = pywraplp.Solver('StudentProjectGridCBC', pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING) | |
# We define the set of assignments that represent a solution; each cell is either 0 or 1. | |
matches = {} | |
for student in STUDENTS: | |
for project in PROJECTS: | |
matches[student, project] = solver.IntVar(0, 1, 'matches[%s,%s]' % (student, project)) | |
# We define the objective function we want to minimize. | |
z = solver.Sum(PREFERENCES[project][student]] * matches[student, project] | |
for student in STUDENTS | |
for project in PROJECTS]) | |
# Constraint: 1 person per project. | |
for student in STUDENTS: | |
solver.Add(solver.Sum([matches[student, project] for project in PROJECTS]) == 1) | |
# Constraint: at least 1 international student per project. | |
for project in PROJECTS: | |
solver.Add(solver.Sum([matches[student, project] * INTERNATIONAL[student]) for student in STUDENTS]) >= 1) | |
# Constraint: good gender diversity. | |
for project in PROJECTS: | |
solver.Add(solver.Sum([matches[student, project] * GENDER[student] for student in STUDENTS]) >= 2) | |
# Constraint: balanced teams. | |
for project in PROJECTS: | |
solver.Add(solver.Sum([matches[student, project] for student in STUDENTS]) >= 3) | |
solver.Add(solver.Sum([matches[student, project] for student in STUDENTS]) <= RATIO) | |
# Constraint: hard-coded assignments. | |
hard_coded_assignments = {"Arnaud": "Crowd Manager", "Neil": "Crowd Manager"} | |
for student in STUDENTS: | |
if student in hard_coded_assignments: | |
solver.Add(matches[student, hard_coded_assignments[student]] == 1) | |
objective = solver.Minimize(z) | |
solver.Solve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment