def getClassSizeConstr(self): vrs = [] for student in self._students: vrs.append(self._students._schedule._lpVars[self._period][int(self._courseCode)]) return summation(vrs), summation(self._instructor._schedule._lpVars[self._period][int(self._courseCode)])
def get_sections_need_teachers_constraints(self): """ Define the LpConstraint ensuring that each section assigned to a student has a qualified teacher assigned to it also. """ all_constraints = [] for student in self.students: for period, lpVars in enumerate(student._schedule._lpVars): for class_id, attending in enumerate(lpVars): # get corresponding qualified teachers teacher_assignment_variables = [] for teacher in self.teachers: if teacher.getQualificationVector()[class_id] == 1: teacher_assignment_variables.append( teacher._schedule._lpVars[period][class_id]) c = summation(teacher_assignment_variables) >= attending all_constraints.append(c) """ Using getGlobalConstr: allConstrs = [] for course in self.courses: allConstrs.append(course.getGlobalConstr()) return allConstrs """ return all_constraints
def getPeriodAttendanceConstraints(self): """ Lazily generate the constraints ensuring that only one section is assigned per period. """ for courseVariables in self._schedule._lpVars: yield summation(courseVariables) <= 1
def getElectiveCost(self) -> int: reqElective = [c.courseCode for c in self.getReqElectives()] for course in self._allCourses: if course._courseCode in reqElective: varList = [] for period in range(self._schedule.periods): variable = self._schedule._lpVars[period][int(course._courseCode)] varList.append(variable) sumOfVariables = summation(varList) yield sumOfVariables
def getGlobalConstr(self): ret = [] for teacher in self._qualifiedTeachers: classindex = teacher.allCourses.index(self._courseCode) for p in range(1, 9): ret.append(teacher.schedule.lpVars[p][classindex]) if self._reqTotalStudents > 0: attending = 1 else: attending = 0 return summation(ret) >= attending
def sectSizeDev(self): """ Returns equation for measuring """ ret = [] avClass = len(self.students) / len(self.teachers) for sect in self.existing_sections: sectStudVariables = [] for stud in sect._students: sectStudVariables.append(stud._schedule._lpVars[sect._period][sect._courseCode]) ret.append(sectStudVariables) return LpAffineExpression(32*len(self.existing_sections) - summation(ret))
def getRequestCheckConstraints(self): """ Lazily generate constraints checking if requested courses appear """ for course in self._allCourses: isRequested = 0 if course in self._reqAll: isRequested = 1 varList = [] for period in range(self._schedule.periods): variable = self._schedule._lpVars[period][int(course._courseCode)] varList.append(variable) sumOfVariables = summation(varList) yield sumOfVariables == isRequested
def getQualifiedTeachingConstraints(self): """ Lazily generate constraints ensuring this teacher only teaches sections that they are qualified to teach. """ for course in self._allCourses: isQualified = 0 if course in self._qualifications: isQualified = 1 varList = [] for period in range(self._schedule.periods): variable = self._schedule._lpVars[period][int(course._courseCode)] varList.append(variable) sumOfVariables = summation(varList) yield sumOfVariables <= isQualified
def getElectiveCost(self) -> int: """ Return an expression equal to the number of requested electives in schedule. """ reqElective = [c._courseCode for c in self.getReqElectives()] for course in self._allCourses: if course._courseCode in reqElective: varList = [ ] # list of Lp variables at this elective and this period for period in range(self._schedule.periods): variable = self._schedule._lpVars[period][int( course._courseCode)] varList.append(variable) # add the sum of variables. This should be 0 or 1 because of other hard # constraints. 1 is good, and since the formula minimizes, the sum should # be subtracted yield -summation(varList)