Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.