use of org.cpsolver.exam.model.ExamPeriodPlacement 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.ExamPeriodPlacement in project cpsolver by UniTime.
the class PeriodPenalty method getBounds.
@Override
public double[] getBounds(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> variables) {
double[] bounds = new double[] { 0.0, 0.0 };
for (Exam exam : variables) {
if (!exam.getPeriodPlacements().isEmpty()) {
int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE;
for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
if (iSoftPeriods != null && (periodPlacement.getExamPenalty() == iSoftPeriods || periodPlacement.getPeriod().getPenalty() == iSoftPeriods))
continue;
minPenalty = Math.min(minPenalty, periodPlacement.getPenalty());
maxPenalty = Math.max(maxPenalty, periodPlacement.getPenalty());
}
bounds[0] += minPenalty;
bounds[1] += maxPenalty;
}
}
return bounds;
}
use of org.cpsolver.exam.model.ExamPeriodPlacement in project cpsolver by UniTime.
the class ExamSplitMoves method bestSplit.
/**
* Find a best split for the given exam. Only improving neighbors are considered.
* @param assignment current assignment
* @param exam an exam to be split
* @return best neighbor that will do the split
*/
public ExamSplitNeighbour bestSplit(Assignment<Exam, ExamPlacement> assignment, Exam exam) {
ExamSplitNeighbour split = null;
ExamPlacement placement = assignment.getValue(exam);
int px = ToolBox.random(exam.getPeriodPlacements().size());
for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
// Iterate over possible periods
ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
if (placement != null && placement.getPeriod().equals(period))
continue;
// Try to create a neighbor
ExamSplitNeighbour s = new ExamSplitNeighbour(assignment, exam, new ExamPlacement(exam, period, null));
if (split == null || s.value(assignment) < split.value(assignment)) {
// If improving, try to find available rooms
Set<ExamRoomPlacement> rooms = findBestAvailableRooms(assignment, exam, period, s.nrStudents());
if (rooms != null) {
// Remember as best split
s.placement().getRoomPlacements().addAll(rooms);
split = s;
}
}
}
return split;
}
Aggregations