use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class PerturbationPenalty 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;
return Math.abs(initial.getPeriod().getIndex() - value.getPeriod().getIndex()) * (1 + exam.getSize());
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class RoomPenalty 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.getRoomPlacements().isEmpty()) {
int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE;
for (ExamRoomPlacement roomPlacement : exam.getRoomPlacements()) {
if (iSoftRooms != null && iSoftRooms == roomPlacement.getPenalty())
continue;
if (!isAvailable(roomPlacement.getRoom()))
continue;
minPenalty = Math.min(minPenalty, 2 * roomPlacement.getPenalty() + getMinPenalty(roomPlacement.getRoom()));
maxPenalty = Math.max(maxPenalty, 2 * roomPlacement.getPenalty() + getMaxPenalty(roomPlacement.getRoom()));
}
bounds[0] += minPenalty;
bounds[1] += maxPenalty;
}
}
return bounds;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class PeriodSizePenalty 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 minSizePenalty = Integer.MAX_VALUE, maxSizePenalty = Integer.MIN_VALUE;
for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) {
minSizePenalty = Math.min(minSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
maxSizePenalty = Math.max(maxSizePenalty, periodPlacement.getPenalty() * (exam.getSize() + 1));
}
bounds[0] += minSizePenalty;
bounds[1] += maxSizePenalty;
}
}
return bounds;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class InstructorDirectConflicts method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
Exam exam = value.variable();
int penalty = 0;
Map<ExamInstructor, Set<Exam>> instructors = ((ExamModel) getModel()).getInstructorsOfPeriod(assignment, value.getPeriod());
for (ExamInstructor s : exam.getInstructors()) {
Set<Exam> exams = instructors.get(s);
if (exams == null)
continue;
int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
if (nrExams > 1)
penalty++;
}
/*
for (ExamInstructor s : exam.getInstructors()) {
Set<Exam> exams = s.getExams(assignment, value.getPeriod());
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 ExamHillClimbing method selectNeighbour.
/**
* Select one of the given neighbourhoods randomly, select neighbour, return
* it if its value is below or equal to zero (continue with the next
* selection otherwise). Return null when the given number of idle
* iterations is reached.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
Context context = getContext(solution.getAssignment());
context.activateIfNeeded();
while (true) {
if (context.incIter(solution))
break;
NeighbourSelection<Exam, ExamPlacement> ns = iNeighbours.get(ToolBox.random(iNeighbours.size()));
Neighbour<Exam, ExamPlacement> n = ns.selectNeighbour(solution);
if (n != null) {
if (n instanceof LazyNeighbour) {
((LazyNeighbour<Exam, ExamPlacement>) n).setAcceptanceCriterion(this);
return n;
} else if (n.value(solution.getAssignment()) <= 0.0)
return n;
}
}
context.reset();
return null;
}
Aggregations