Last active
May 4, 2018 00:26
-
-
Save amueller/8866e02e5132c999fa9f7b0c8b8977df 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
import cvxpy as cvx | |
n_students = 130 | |
n_projects = 30 | |
assignment = cvx.Int(rows=n_students, cols=n_projects) | |
import numpy as np | |
rng = np.random.RandomState(0) | |
project_preferences = rng.rand(n_students, n_projects) | |
constraints = [cvx.sum_entries(assignment, axis=0) >= 4, | |
cvx.sum_entries(assignment, axis=0) <= 5, | |
cvx.sum_entries(assignment, axis=1) == 1, | |
assignment >=0, assignment <= 1] | |
# This works: | |
obj = cvx.Maximize(cvx.sum_entries(cvx.mul_elemwise(project_preferences, assignment))) | |
prob = cvx.Problem(obj, constraints) | |
prob.solve() | |
res = np.array(assignment.value) | |
# this is non-linear aka not allowed. | |
student_preferences = rng.rand(n_students, n_students) | |
obj = cvx.Maximize(cvx.sum_entries(cvx.mul_elemwise(project_preferences, assignment)) + | |
cvx.sum_entries(cvx.mul_elemwise(student_preferences, (assignment * assignment.T)))) | |
prob = cvx.Problem(obj, constraints) | |
prob.solve() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment