using Convex, GLPKMathProgInterface # data.jl has our preference matrix, P include("data.jl"); # Specify the variables # HINT: check what size P has ;) X = # We want every student to be assigned to exactly one section. # So, every row must have exactly one non-zero entry # In other words, the sum of all the columns for every row is 1 # We also want each section to have between 6 and 10 students, # so the sum of all the rows for every column should be between these # Specify the constraints # HINT: you can do it on one line, but it's also # okay to do it on multiple lines. # if you wish to add a constraint later on # you can do so by: # constraints += ... constraints = # Our objective is simple sum(X .* P), which can be # more efficiently represented as vec(X)' * vec(P) # Since each entry of X is either 0 or 1, # this is basically summing up the rankings of students # that were assigned to them. # If all students got their first choice, # this value will be the number of students since # the ranking of the first choice is 1. p = # I specified the solver for you :) @time solve!(p, GLPKSolverMIP()) p.optval # correct answer is 65.0 ...