use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamRandomMove method selectNeighbour.
/**
* Select an exam randomly, select an available period randomly (from
* {@link Exam#getPeriodPlacements()}), select rooms using
* {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)}.
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
ExamModel model = (ExamModel) solution.getModel();
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
Exam exam = ToolBox.random(model.variables());
int px = ToolBox.random(exam.getPeriodPlacements().size());
for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
continue;
if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
continue;
Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
if (rooms == null)
continue;
return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
}
return null;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamTimeMove method selectNeighbour.
/**
* Select an exam randomly,
* select an available period randomly (if it is not assigned),
* use rooms if possible, select rooms using {@link Exam#findBestAvailableRooms(Assignment, ExamPeriodPlacement)} if not (exam is unassigned, a room is not available or used).
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
ExamModel model = (ExamModel) solution.getModel();
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
ExamRoomSharing sharing = model.getRoomSharing();
Exam exam = ToolBox.random(model.variables());
ExamPlacement placement = assignment.getValue(exam);
int px = ToolBox.random(exam.getPeriodPlacements().size());
for (int p = 0; p < exam.getPeriodPlacements().size(); p++) {
ExamPeriodPlacement period = exam.getPeriodPlacements().get((p + px) % exam.getPeriodPlacements().size());
if (placement != null && placement.getPeriod().equals(period))
continue;
if (iCheckStudentConflicts && exam.countStudentConflicts(assignment, period) > 0)
continue;
if (iCheckDistributionConstraints && !exam.checkDistributionConstraints(assignment, period))
continue;
if (placement != null) {
boolean ok = true;
if (sharing != null && placement.getRoomPlacements().size() == 1) {
ExamRoomPlacement room = placement.getRoomPlacements().iterator().next();
ok = room.isAvailable(period.getPeriod()) && !sharing.inConflict(exam, room.getRoom().getPlacements(assignment, period.getPeriod()), room.getRoom());
} else {
for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
ExamRoomPlacement room = i.next();
if (!room.isAvailable(period.getPeriod()) || !room.getRoom().getPlacements(assignment, period.getPeriod()).isEmpty()) {
ok = false;
break;
}
}
}
if (ok)
return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, placement.getRoomPlacements()));
}
Set<ExamRoomPlacement> rooms = exam.findBestAvailableRooms(assignment, period);
if (rooms == null)
continue;
return new ExamSimpleNeighbour(assignment, new ExamPlacement(exam, period, rooms));
}
return null;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class StudentNotAvailableConflicts method getValue.
@Override
public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
Exam exam = value.variable();
int penalty = 0;
for (ExamStudent s : exam.getStudents()) {
if (!s.isAvailable(value.getPeriod()))
penalty++;
}
return penalty;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class DistributionViolation 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() || getWeight() != dc.getWeight())
continue;
if (!dc.isSatisfied(assignment))
penalty += 1;
}
}
}
return penalty;
}
use of org.cpsolver.exam.model.Exam in project cpsolver by UniTime.
the class ExamSplitter method getInfo.
/**
* Lists the split
*/
@Override
public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
if (!iChildren.isEmpty()) {
int parents = 0;
String split = "";
for (Exam parent : new TreeSet<Exam>(iChildren.keySet())) {
List<Exam> children = iChildren.get(parent);
if (children.isEmpty())
continue;
split += "\n ";
parents++;
split += parent.getName() + ": " + parent.getStudents().size() + " (" + (assignment.getValue(parent) == null ? "N/A" : assignment.getValue(parent).getPeriod()) + ")";
for (Exam child : children) split += " + " + child.getStudents().size() + " (" + (assignment.getValue(child) == null ? "N/A" : assignment.getValue(child).getPeriod()) + ")";
}
if (parents > 0)
info.put("Examination Splits", parents + split);
}
}
Aggregations