use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamCriterion method getBounds.
@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
double[] bounds = new double[] { 0.0, 0.0 };
for (Exam exam : exams) {
Double min = null, max = null;
for (ExamPeriodPlacement period : exam.getPeriodPlacements()) {
if (exam.getMaxRooms() == 0) {
double value = getValue(assignment, new ExamPlacement(exam, period, null), null);
if (min == null) {
min = value;
max = value;
continue;
}
min = Math.min(min, value);
max = Math.max(max, value);
} else {
for (ExamRoomPlacement room : exam.getRoomPlacements()) {
Set<ExamRoomPlacement> rooms = new HashSet<ExamRoomPlacement>();
rooms.add(room);
double value = getValue(assignment, new ExamPlacement(exam, period, rooms), null);
if (min == null) {
min = value;
max = value;
continue;
}
min = Math.min(min, value);
max = Math.max(max, value);
}
}
}
if (min != null) {
bounds[0] += min;
bounds[1] += max;
}
}
return bounds;
}
use of org.cpsolver.exam.model.Exam 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