$title Assigning students to projects to maximize overall satisfaction option limrow=0, limcol=0, solprint=off; $ontext A teacher wishes to assign 5 projects to 5 different students. Each student has indicated their preference for each project by assigning it a score between 0 and 10 (0 indicating strong dislike and 10 indicating strong preference). The teacher wishes to make the assignment of projects to students in a way that maximizes their overall satisfaction, as measured by the sum of the preferences for the given assignments. $offtext set projects/proj1*proj5/ students/student1*student5/ ; table preferences(students,projects) proj1 proj2 proj3 proj4 proj5 student1 7 5 5 2 8 student2 2 3 4 8 5 student3 7 0 4 4 7 student4 8 2 3 7 3 student5 6 2 4 6 0 ; * want x to be 1 if that student is assigned to that project; 0 otherwise binary variable x(students,projects) ; * (actually in this simple assignment problem, dont need the variables to * be binary) variable satisfaction; equations EQassignProjects(projects) EQassignStudents(students) objective ; * ensure that each project is assigned to one of the student EQassignProjects(projects).. sum(students, x(students,projects)) =e= 1; * ensure that each students is assigned exactly one project EQassignStudents(students).. sum(projects, x(students,projects)) =e= 1; * satisfaction index objective.. satisfaction =e= sum((students,projects), x(students,projects) * preferences(students,projects)); model happyclass/EQassignProjects, EQassignStudents,objective/; solve happyclass using mip maximizing satisfaction; * define a set to display the solution in a nice way set matchings(students,projects) ; matchings(students,projects) = yes$(x.l(students,projects) > 0); * display in list format option matchings:0:0:1; display matchings;