use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.
the class DomainChart method createTable.
public CSVFile createTable() {
computeTable();
CSVFile csv = new CSVFile();
CSVFile.CSVField[] header = new CSVFile.CSVField[2 + iSizeX + (iShowZero ? 1 : 0)];
header[0] = new CSVFile.CSVField(iName);
for (int i = (iShowZero ? 0 : 1); i <= iSizeX + 1; i++) header[(iShowZero ? 1 : 0) + i] = new CSVFile.CSVField(iHeader[i]);
csv.setHeader(header);
for (int y = (iShowZero ? 0 : 1); y <= 1 + iSizeY; y++) {
CSVFile.CSVField[] line = new CSVFile.CSVField[2 + iSizeX + (iShowZero ? 1 : 0)];
line[0] = new CSVFile.CSVField(iTitle[y]);
if (y == 1 + iSizeY)
line[0] = new CSVFile.CSVField((1 + iSizeY) + "+");
for (int x = (iShowZero ? 0 : 1); x <= 1 + iSizeX; x++) line[(iShowZero ? 1 : 0) + x] = new CSVFile.CSVField(iTable[x][y]);
csv.addLine(line);
}
return csv;
}
use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.
the class ExamAssignments 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("Alt"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Room"), new CSVField("Cap") });
for (Exam exam : iModel.variables()) {
ExamPlacement placement = assignment.getValue(exam);
ArrayList<CSVField> fields = new ArrayList<CSVField>();
fields.add(new CSVField(exam.getName()));
fields.add(new CSVField(exam.getStudents().size()));
fields.add(new CSVField(exam.hasAltSeating() ? "Yes" : "No"));
if (placement == null) {
fields.add(new CSVField(""));
fields.add(new CSVField(""));
fields.add(new CSVField(""));
fields.add(new CSVField(""));
fields.add(new CSVField(""));
} else {
fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
fields.add(new CSVField(placement.getPeriod().getDayStr()));
fields.add(new CSVField(placement.getPeriod().getTimeStr()));
String rooms = "";
String roomSizes = "";
for (Iterator<ExamRoomPlacement> i = placement.getRoomPlacements().iterator(); i.hasNext(); ) {
ExamRoomPlacement room = i.next();
rooms += room.getRoom().getName();
roomSizes += room.getSize(exam.hasAltSeating());
if (i.hasNext()) {
rooms += ", ";
roomSizes += ", ";
}
}
fields.add(new CSVField(rooms));
fields.add(new CSVField(roomSizes));
}
csv.addLine(fields);
}
return csv;
}
use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.
the class ExamInstructorConflicts 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("Instructor"), new CSVField("Type"), new CSVField("Section/Course"), new CSVField("Period"), new CSVField("Day"), new CSVField("Time"), new CSVField("Room"), new CSVField("Distance") });
boolean isDayBreakBackToBack = ((InstructorBackToBackConflicts) iModel.getCriterion(InstructorBackToBackConflicts.class)).isDayBreakBackToBack();
double backToBackDistance = ((InstructorDistanceBackToBackConflicts) iModel.getCriterion(InstructorDistanceBackToBackConflicts.class)).getBackToBackDistance();
for (ExamInstructor instructor : iModel.getInstructors()) {
for (ExamPeriod period : iModel.getPeriods()) {
int nrExams = instructor.getExams(assignment, period).size();
if (nrExams > 1) {
String sections = "";
String rooms = "";
String periods = String.valueOf(period.getIndex() + 1);
String periodDays = period.getDayStr();
String periodTimes = period.getTimeStr();
for (Exam exam : instructor.getExams(assignment, period)) {
ExamPlacement placement = assignment.getValue(exam);
String roomsThisExam = "";
for (ExamRoomPlacement room : placement.getRoomPlacements()) {
if (roomsThisExam.length() > 0)
roomsThisExam += ", ";
roomsThisExam += room.getName();
}
boolean first = true;
for (ExamOwner owner : exam.getOwners(instructor)) {
if (sections.length() > 0) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
}
sections += owner.getName();
if (first)
rooms += roomsThisExam;
first = false;
}
if (exam.getOwners(instructor).isEmpty()) {
sections += exam.getName();
rooms += roomsThisExam;
}
}
csv.addLine(new CSVField[] { new CSVField(instructor.getName()), new CSVField("direct"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms) });
}
if (nrExams > 0) {
if (period.next() != null && !instructor.getExams(assignment, period.next()).isEmpty() && (!isDayBreakBackToBack || period.next().getDay() == period.getDay())) {
for (Exam ex1 : instructor.getExams(assignment, period)) {
for (Exam ex2 : instructor.getExams(assignment, period.next())) {
ExamPlacement placement = assignment.getValue(ex1);
String sections = "";
String rooms = "";
String roomsThisExam = "";
String periods = String.valueOf(period.getIndex() + 1);
String periodDays = period.getDayStr();
String periodTimes = period.getTimeStr();
for (ExamRoomPlacement room : placement.getRoomPlacements()) {
if (roomsThisExam.length() > 0)
roomsThisExam += ", ";
roomsThisExam += room.getName();
}
boolean first = true;
for (ExamOwner owner : ex1.getOwners(instructor)) {
if (sections.length() > 0) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
}
sections += owner.getName();
if (first)
rooms += roomsThisExam;
first = false;
}
if (ex1.getOwners(instructor).isEmpty()) {
sections += ex1.getName();
rooms += roomsThisExam;
}
placement = assignment.getValue(ex2);
roomsThisExam = "";
for (ExamRoomPlacement room : placement.getRoomPlacements()) {
if (roomsThisExam.length() > 0)
roomsThisExam += ", ";
roomsThisExam += room.getName();
}
first = true;
for (ExamOwner owner : ex2.getOwners(instructor)) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
sections += owner.getName();
if (first) {
rooms += roomsThisExam;
periods += String.valueOf(period.next().getIndex() + 1);
periodDays += period.next().getDayStr();
periodTimes += period.next().getTimeStr();
}
first = false;
}
if (ex2.getOwners(instructor).isEmpty()) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
sections += ex2.getName();
rooms += roomsThisExam;
periods += String.valueOf(period.next().getIndex() + 1);
periodDays += period.next().getDayStr();
periodTimes += period.next().getTimeStr();
}
String distStr = "";
if (backToBackDistance >= 0) {
double dist = (assignment.getValue(ex1)).getDistanceInMeters(assignment.getValue(ex2));
if (dist > 0)
distStr = String.valueOf(dist);
}
csv.addLine(new CSVField[] { new CSVField(instructor.getName()), new CSVField("back-to-back"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms), new CSVField(distStr) });
}
}
}
}
if (period.next() == null || period.next().getDay() != period.getDay()) {
int nrExamsADay = instructor.getExamsADay(assignment, period.getDay()).size();
if (nrExamsADay > 2) {
String sections = "";
String periods = "";
String periodDays = "";
String periodTimes = "";
String rooms = "";
for (Exam exam : instructor.getExamsADay(assignment, period.getDay())) {
ExamPlacement placement = assignment.getValue(exam);
String roomsThisExam = "";
for (ExamRoomPlacement room : placement.getRoomPlacements()) {
if (roomsThisExam.length() > 0)
roomsThisExam += ", ";
roomsThisExam += room.getName();
}
boolean first = true;
for (ExamOwner owner : exam.getOwners(instructor)) {
if (sections.length() > 0) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
}
sections += owner.getName();
if (first) {
periods += (placement.getPeriod().getIndex() + 1);
periodDays += placement.getPeriod().getDayStr();
periodTimes += placement.getPeriod().getTimeStr();
rooms += roomsThisExam;
}
first = false;
}
if (exam.getOwners(instructor).isEmpty()) {
if (sections.length() > 0) {
sections += "\n";
rooms += "\n";
periods += "\n";
periodDays += "\n";
periodTimes += "\n";
}
sections += exam.getName();
periods += (placement.getPeriod().getIndex() + 1);
periodDays += placement.getPeriod().getDayStr();
periodTimes += placement.getPeriod().getTimeStr();
rooms += roomsThisExam;
}
}
csv.addLine(new CSVField[] { new CSVField(instructor.getName()), new CSVField("more-2-day"), new CSVField(sections), new CSVField(periods), new CSVField(periodDays), new CSVField(periodTimes), new CSVField(rooms) });
}
}
}
}
return csv;
}
use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.
the class ExamRoomSchedule method report.
public CSVFile report(Assignment<Exam, ExamPlacement> assignment) {
CSVFile csv = new CSVFile();
csv.setHeader(new CSVField[] { new CSVField("Room"), new CSVField("Cap"), new CSVField("AltCap"), new CSVField("Period"), new CSVField("Date"), new CSVField("Time"), new CSVField("Exam"), new CSVField("Enrl") });
List<ExamRoom> rooms = new ArrayList<ExamRoom>(iModel.getRooms());
Collections.sort(rooms, new Comparator<ExamRoom>() {
@Override
public int compare(ExamRoom r1, ExamRoom r2) {
int cmp = -Double.compare(r1.getSize(), r2.getSize());
if (cmp != 0)
return cmp;
cmp = -Double.compare(r1.getAltSize(), r2.getAltSize());
if (cmp != 0)
return cmp;
return r1.compareTo(r2);
}
});
for (ExamRoom room : rooms) {
boolean first = true;
int day = -1;
for (ExamPeriod period : iModel.getPeriods()) {
for (ExamPlacement placement : room.getPlacements(assignment, period)) {
Exam exam = placement.variable();
csv.addLine(new CSVField[] { new CSVField(first ? room.getName() : ""), new CSVField(first ? "" + room.getSize() : ""), new CSVField(first ? "" + room.getAltSize() : ""), new CSVField(period.getIndex() + 1), new CSVField(day == period.getDay() ? "" : period.getDayStr()), new CSVField(period.getTimeStr()), new CSVField(exam.getName()), new CSVField(exam.getStudents().size()) });
first = false;
day = period.getDay();
}
}
}
return csv;
}
use of org.cpsolver.ifs.util.CSVFile in project cpsolver by UniTime.
the class ExamStudentBackToBackConflicts 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("Back-To-Back"), new CSVField("Back-To-Back [%]"), new CSVField("Distance") });
DecimalFormat df = new DecimalFormat("0.0");
boolean isDayBreakBackToBack = ((StudentBackToBackConflicts) iModel.getCriterion(StudentBackToBackConflicts.class)).isDayBreakBackToBack();
double backToBackDistance = ((StudentDistanceBackToBackConflicts) iModel.getCriterion(StudentDistanceBackToBackConflicts.class)).getBackToBackDistance();
for (Exam ex1 : iModel.variables()) {
ExamPlacement p1 = assignment.getValue(ex1);
if (p1 == null || p1.getPeriod().next() == null)
continue;
if (!isDayBreakBackToBack && p1.getPeriod().getDay() != p1.getPeriod().next().getDay())
continue;
for (Exam ex2 : iModel.variables()) {
ExamPlacement p2 = assignment.getValue(ex2);
if (p2 == null || !p2.getPeriod().equals(p1.getPeriod().next()))
continue;
List<ExamStudent> students = ex1.getJointEnrollments().get(ex2);
if (students == null || students.isEmpty())
continue;
String distStr = "";
if (backToBackDistance >= 0) {
double dist = p1.getDistanceInMeters(p2);
if (dist > 0)
distStr = String.valueOf(dist);
}
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()))), new CSVField(distStr) });
}
}
return csv;
}
Aggregations