def add_rotation_sym_constraints(self, problem): problem.addConstraint( constraint.FunctionConstraint(rotation_90(self.n_rows()), self.rows())) problem.addConstraint( constraint.FunctionConstraint(rotation_180(self.n_rows()), self.rows())) problem.addConstraint( constraint.FunctionConstraint(rotation_270(self.n_rows()), self.rows()))
def add_axes_sym_constraints(self, problem): problem.addConstraint( constraint.FunctionConstraint(horizontal_symetry(self.n_rows()), self.rows())) problem.addConstraint(constraint.FunctionConstraint(vertical_symetry), self.rows()) problem.addConstraint( constraint.FunctionConstraint(diag_symetry(self.n_rows()), self.rows())) problem.addConstraint( constraint.FunctionConstraint(anti_diag_symetry(self.n_rows()), self.rows()))
def sym_constraints(self, problem): problem.addConstraint( constraint.FunctionConstraint(lambda x, y: x - y < 0), [self.rows()[i] for i in [0, -1]]) problem.addConstraint( constraint.MaxSumConstraint((self.n_cols() + 1) / 2), [self.rows()[0]])
def add_diag_right_constraints(self, problem): """add_box_constraints(problem, boxsize) Adds to constraint problem 'problem', all_different constraints on boxes.""" for i, j in itertools.combinations(self.rows(), 2): problem.addConstraint( constraint.FunctionConstraint(self.right_constraint(i, j)), [i, j])
def __init__(self): self.credit_limit = 120 self.theo_limit = 10 self.area_limit = [18, 8, 8] self.max_allowed_lectures = 8 # In Master it is unrealistic to do more than N lectures (except thesis practical courses seminars etc.) self.taken_lecture_names = ['Computer Vision I: Variational Methods', 'Computer Vision II: Multiple View Geometry', 'Natural Language Processing', 'Introduction to Deep Learning', 'Advanced Deep Learning for Computer Vision'] self.preferred_areas = ['COMPUTER GRAPHICS AND VISION', 'MACHINE LEARNING AND ANALYTICS', 'DIGITAL BIOLOGY AND DIGITAL MEDICINE'] self.problem = constraint.Problem() self.lectures = self.create_lectures() self.taken_lectures = [] for lecture in self.lectures: if lecture.name in self.taken_lecture_names: self.taken_lectures.append(lecture) for taken_lecture in self.taken_lectures: self.lectures.remove(taken_lecture) self.taken_lectures.extend( # Not classical lectures [Lecture(name='Seminar', ec=5, area='None'), Lecture(name='Practical Course', ec=10, area='None'), Lecture(name='IDP', ec=16, area='None'), Lecture(name='Guided Research', ec=10, area='None'), Lecture(name='Thesis', ec=30, area='None'), Lecture(name='Language', ec=6, area='None')]) self.exitings_credits = 0 self.existing_theo_credits = 0 for taken_lecture in self.taken_lectures: self.exitings_credits += taken_lecture.ec if taken_lecture.theo: self.existing_theo_credits += taken_lecture.ec self.lectures = sorted(self.lectures) self.problem.addVariables(self.lectures, [0, 1]) self.problem.addConstraint(constraint.MaxSumConstraint(self.max_allowed_lectures - len(self.taken_lecture_names)), self.lectures) self.problem.addConstraint(constraint.FunctionConstraint(self.area_constraint), self.lectures) self.problem.addConstraint(constraint.FunctionConstraint(self.credit_constraint), self.lectures) self.problem.addConstraint(constraint.FunctionConstraint(self.theo_constraint), self.lectures) start = time() solutions = self.problem.getSolutions() print(f'Took {time() - start}') print(len(solutions)) solutions = self.solution_sorting(solutions) print(len(solutions)) for i in range(100): print(self.get_credits_for_solution(solutions[i])) print(self.solution_to_str(solutions[i]))
return True def borderRightConstraintFunction(a1, b1, a2, b2, a3, b3, assignments=None, _unassigned=csp.Unassigned): if b2 == bow_left: return False if (not noNeighbourConstraintFunction(a1, b1, 7, a2, b2, 7, a3, b3, 7, _unassigned)): return False return True for rowIndex, numberOfParts in enumerate(parts_in_row): row = rows[rowIndex] constraint = csp.FunctionConstraint(getNumberOfPartsConstraint( numberOfParts, rowIndex=rowIndex), assigned=debugAssigned) bimaru.addConstraint(constraint, row) for colIndex, numberOfParts in enumerate(parts_in_col): col = cols[colIndex] constraint = csp.FunctionConstraint(getNumberOfPartsConstraint( numberOfParts, colIndex=colIndex), assigned=debugAssigned) bimaru.addConstraint(constraint, col) noNeighbourConstraint = csp.FunctionConstraint( noNeighbourConstraintFunction, assigned=debugAssigned) for box in boxes: bimaru.addConstraint(noNeighbourConstraint, box) borderTopConstraint = csp.FunctionConstraint(