However, you may want to really think about the structure of your problem and realize there are two or more sub-problems within it. To me, it sounds like you'll want to do a separate optimization to generate the schedule, then do another optimization problem that assigns students to those scheduled classes. You will need to define some score/ranking on how desirable each student-class pairing is, and maximize the sum of those assignments.