use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.
the class ExamStudentDirectConflicts method report.
/**
* generate report
* @param assignment current assignment
* @return resultant report
*/
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
CSVFile csv = new CSVFile();
csv.setHeader(new CSVField[] { new CSVField("Exam 1"), new CSVField("Enrl 1"), new CSVField("Period 1"), new CSVField("Date 1"), new CSVField("Time 1"), new CSVField("Exam 2"), new CSVField("Enrl 2"), new CSVField("Direct"), new CSVField("Direct [%]") });
DecimalFormat df = new DecimalFormat("0.0");
for (Exam ex1 : iModel.variables()) {
ExamPlacement p1 = assignment.getValue(ex1);
if (p1 == null)
continue;
for (Exam ex2 : iModel.variables()) {
if (ex1.getId() >= ex2.getId())
continue;
ExamPlacement p2 = assignment.getValue(ex2);
if (p2 == null || !p2.getPeriod().equals(p1.getPeriod()))
continue;
List<ExamStudent> students = ex1.getJointEnrollments().get(ex2);
if (students == null || students.isEmpty())
continue;
csv.addLine(new CSVField[] { new CSVField(ex1.getName()), new CSVField(ex1.getStudents().size()), new CSVField(p1.getPeriod().getIndex() + 1), new CSVField(p1.getPeriod().getDayStr()), new CSVField(p1.getPeriod().getTimeStr()), new CSVField(ex2.getName()), new CSVField(ex2.getStudents().size()), new CSVField(students.size()), new CSVField(df.format(100.0 * students.size() / Math.min(ex1.getStudents().size(), ex2.getStudents().size()))) });
}
}
return csv;
}
use of org.cpsolver.exam.model.ExamPlacement 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;
}
use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.
the class ExamSplitMoves method selectNeighbour.
/**
* Select a split (split an exam into two), a merge (merge two split exams back together) or
* shuffle operation (move students between two exams that has been split before).
*/
@Override
public Neighbour<Exam, ExamPlacement> selectNeighbour(Solution<Exam, ExamPlacement> solution) {
// Randomly select an exam
Exam exam = ToolBox.random(solution.getAssignment().assignedVariables());
Assignment<Exam, ExamPlacement> assignment = solution.getAssignment();
// Parent exam (its either the exam itself, or its parent if it has been already split)
Exam parent = iSplitter.parent(exam);
// Its children (if already split)
List<Exam> children = iSplitter.children(parent);
// Already split -> try shuffle
if (children != null && !children.isEmpty()) {
ExamShuffleNeighbour shuffle = new ExamShuffleNeighbour(assignment, exam);
if (shuffle.value(assignment) < 0.0)
return shuffle;
}
// Can split -> try a split
if (iSplitter.canSplit(exam)) {
ExamSplitNeighbour split = bestSplit(solution.getAssignment(), exam);
if (split != null && split.value(assignment) < 0.0)
return split;
}
// Can merge -> try to merge
if (iSplitter.canMerge(exam)) {
ExamMergeNeighbour merge = new ExamMergeNeighbour(assignment, exam);
if (merge.value(assignment) < 0.0)
return merge;
}
return null;
}
use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.
the class ExamRoomSplit method report.
/**
* generate report
* @param assignment current assignment
* @return resultant report
*/
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
CSVFile csv = new CSVFile();
csv.setHeader(new CSVField[] { new CSVField("Exam"), new CSVField("Enrl"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Room 1"), new CSVField("Cap 1"), new CSVField("Room 2"), new CSVField("Cap 2"), new CSVField("Room 3"), new CSVField("Cap 3"), new CSVField("Room 4"), new CSVField("Cap 4") });
for (Exam exam : iModel.variables()) {
ExamPlacement placement = assignment.getValue(exam);
if (placement == null || placement.getRoomPlacements().size() <= 1)
continue;
List<CSVField> fields = new ArrayList<CSVField>();
fields.add(new CSVField(exam.getName()));
fields.add(new CSVField(exam.getStudents().size()));
fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
fields.add(new CSVField(placement.getPeriod().getDayStr()));
fields.add(new CSVField(placement.getPeriod().getTimeStr()));
TreeSet<ExamRoomPlacement> rooms = new TreeSet<ExamRoomPlacement>(new ExamRoomComparator(exam, false));
rooms.addAll(placement.getRoomPlacements());
for (ExamRoomPlacement room : rooms) {
fields.add(new CSVField(room.getName()));
fields.add(new CSVField(room.getSize(exam.hasAltSeating())));
}
csv.addLine(fields);
}
return csv;
}
use of org.cpsolver.exam.model.ExamPlacement in project cpsolver by UniTime.
the class MistaTables method main.
public static void main(String[] args) {
try {
ToolBox.configureLogging();
DataProperties config = new DataProperties();
Table[] tables = new Table[] { new Problems(), new Rooms() };
for (int i = 0; i < args.length; i++) {
File file = new File(args[i]);
sLog.info("Loading " + file);
ExamModel model = new ExamModel(config);
Assignment<Exam, ExamPlacement> assignment = new DefaultSingleAssignment<Exam, ExamPlacement>();
model.load(new SAXReader().read(file), assignment);
String name = file.getName();
if (name.contains("."))
name = name.substring(0, name.indexOf('.'));
for (Table table : tables) table.add(name, model);
Progress.removeInstance(model);
}
sLog.info("Saving tables...");
File output = new File("tables");
output.mkdir();
for (Table table : tables) table.save(output);
sLog.info("All done.");
} catch (Exception e) {
sLog.error(e.getMessage(), e);
}
}
Aggregations