use of org.cpsolver.exam.model.ExamModel in project cpsolver by UniTime.
the class StudentDirectConflicts method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
Exam exam = value.variable();
int penalty = 0;
ExamPeriod period = value.getPeriod();
ExamModel m = (ExamModel) getModel();
Map<ExamStudent, Set<Exam>> students = m.getStudentsOfPeriod(assignment, period);
for (ExamStudent s : exam.getStudents()) {
Set<Exam> exams = students.get(s);
if (exams == null)
continue;
int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
if (nrExams > 1)
penalty++;
}
if (m.isCheckForPeriodOverlaps()) {
for (ExamPeriod p : m.getPeriods()) {
if (period.hasIntersection(p)) {
Map<ExamStudent, Set<Exam>> others = m.getStudentsOfPeriod(assignment, p);
s: for (ExamStudent s : exam.getStudents()) {
Set<Exam> exams = students.get(s);
if (exams == null || exams.size() + (exams.contains(exam) ? 0 : 1) <= 1) {
Set<Exam> other = others.get(s);
if (other != null && !other.isEmpty())
for (Exam x : other) {
if (period.hasIntersection(exam, x, p)) {
penalty++;
continue s;
}
}
}
}
}
}
}
/*
for (ExamStudent s : exam.getStudents()) {
Set<Exam> exams = s.getExams(assignment, period);
if (exams.isEmpty()) continue;
int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
if (nrExams > 1)
penalty++;
}
*/
return penalty;
}
use of org.cpsolver.exam.model.ExamModel in project cpsolver by UniTime.
the class InstructorBackToBackConflicts method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
Exam exam = value.variable();
int penalty = 0;
ExamPeriod period = value.getPeriod();
Map<ExamInstructor, Set<Exam>> prev = (period.prev() != null && (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) ? ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, period.prev()) : null);
Map<ExamInstructor, Set<Exam>> next = (period.next() != null && (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) ? ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, period.next()) : null);
for (ExamInstructor s : exam.getInstructors()) {
if (prev != null) {
Set<Exam> exams = prev.get(s);
if (exams != null) {
int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
penalty += nrExams;
}
}
if (next != null) {
Set<Exam> exams = next.get(s);
if (exams != null) {
int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
penalty += nrExams;
}
}
}
/*
for (ExamInstructor s : exam.getInstructors()) {
if (period.prev() != null) {
if (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) {
Set<Exam> exams = s.getExams(assignment, period.prev());
int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
penalty += nrExams;
}
}
if (period.next() != null) {
if (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) {
Set<Exam> exams = s.getExams(assignment, period.next());
int nrExams = exams.size() + (exams.contains(exam) ? -1 : 0);
penalty += nrExams;
}
}
}
*/
return penalty;
}
Aggregations