use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class DistributionPenalty method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
int penalty = 0;
Set<ExamDistributionConstraint> added = new HashSet<ExamDistributionConstraint>();
for (Exam exam : variables) {
for (ExamDistributionConstraint dc : exam.getDistributionConstraints()) {
if (added.add(dc)) {
if (dc.isHard() || (iSoftDistributions != null && iSoftDistributions == dc.getWeight()))
continue;
if (!dc.isSatisfied(assignment))
penalty += dc.getWeight();
}
}
}
return penalty;
}
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 RoomPerturbationPenalty method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
if (!isMPP())
return 0;
Exam exam = value.variable();
ExamPlacement initial = exam.getInitialAssignment();
if (initial == null)
return 0;
int penalty = 0;
if (value.getRoomPlacements() != null)
for (ExamRoomPlacement rp : value.getRoomPlacements()) {
if (initial.getRoomPlacements() == null || !initial.getRoomPlacements().contains(rp))
penalty++;
}
return penalty;
}
use of org.cpsolver.exam.model.Exam 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();
Map<ExamStudent, Set<Exam>> students = ((ExamModel) getModel()).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++;
}
/*
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.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