use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamSimulatedAnnealing method selectNeighbour.
/**
* Select neighbour -- generate a move
* {@link ExamSimulatedAnnealing#genMove(Solution)} until an acceptable
* neighbour is found
* {@link ExamSimulatedAnnealing#accept(Solution, Neighbour)}, keep
* increasing iteration {@link ExamSimulatedAnnealing.Context#incIter(Solution)}.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
Context context = getContext(solution.getAssignment());
context.activateIfNeeded();
Neighbour<Exam, ExamPlacement> neighbour = null;
while ((neighbour = genMove(solution)) != null) {
context.incMoves(neighbour.value(solution.getAssignment()));
if (accept(solution, neighbour))
break;
}
if (neighbour == null)
context.reset();
return (neighbour == null ? null : neighbour);
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamSimulatedAnnealing method accept.
/**
* True if the given neighboir is to be be accepted
*
* @param solution
* current solution
* @param neighbour
* proposed move
* @return true if generated random number is below
* {@link ExamSimulatedAnnealing.Context#prob(double)}
*/
protected boolean accept(Solution<Exam, ExamPlacement> solution, Neighbour<Exam, ExamPlacement> neighbour) {
if (neighbour instanceof LazyNeighbour) {
((LazyNeighbour<Exam, ExamPlacement>) neighbour).setAcceptanceCriterion(this);
return true;
}
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
double value = (iRelativeAcceptance ? neighbour.value(assignment) : solution.getModel().getTotalValue(assignment) + neighbour.value(assignment) - solution.getBestValue());
Context context = getContext(solution.getAssignment());
double prob = context.prob(value);
if (prob >= 1.0 || ToolBox.random() < prob) {
context.accepted(neighbour.value(assignment));
return true;
}
return false;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class StudentMoreThan2ADayConflicts 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()).getStudentsOfDay(assignment, period);
for (ExamStudent s : exam.getStudents()) {
Set<Exam> exams = students.get(s);
if (exams == null || exams.size() < 2)
continue;
int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
if (nrExams > 2)
penalty++;
}
/*
for (ExamStudent s : exam.getStudents()) {
Set<Exam> exams = s.getExamsADay(assignment, period);
int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
if (nrExams > 2)
penalty++;
}
*/
return penalty;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class RoomSizePenalty method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
Exam exam = value.variable();
int size = 0;
if (value.getRoomPlacements() != null)
for (ExamRoomPlacement r : value.getRoomPlacements()) {
size += r.getSize(exam.hasAltSeating());
}
int diff = size - exam.getSize();
return (diff < 0 ? 0 : Math.pow(diff, iRoomSizeFactor));
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class StudentBackToBackConflicts 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>> prev = (period.prev() != null && (isDayBreakBackToBack() || period.prev().getDay() == period.getDay()) ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.prev()) : null);
Map<ExamStudent, Set<Exam>> next = (period.next() != null && (isDayBreakBackToBack() || period.next().getDay() == period.getDay()) ? ((ExamModel) getModel()).getStudentsOfPeriod(assignment, period.next()) : null);
for (ExamStudent s : exam.getStudents()) {
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 (ExamStudent s : exam.getStudents()) {
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