001 package net.sf.cpsolver.exam.reports;
002
003 import java.util.ArrayList;
004 import java.util.List;
005 import java.util.TreeSet;
006
007 import net.sf.cpsolver.exam.model.Exam;
008 import net.sf.cpsolver.exam.model.ExamModel;
009 import net.sf.cpsolver.exam.model.ExamPlacement;
010 import net.sf.cpsolver.exam.model.ExamRoomPlacement;
011 import net.sf.cpsolver.ifs.util.CSVFile;
012 import net.sf.cpsolver.ifs.util.CSVFile.CSVField;
013
014 /**
015 * Export room splitting into a CSV file. <br>
016 * <br>
017 * Usage:<br>
018 * <code>
019 * new ExamRoomSplit(model).report().save(file);
020 * </code> <br>
021 * <br>
022 *
023 * @version ExamTT 1.2 (Examination Timetabling)<br>
024 * Copyright (C) 2007 - 2010 Tomas Muller<br>
025 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
026 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
027 * <br>
028 * This library is free software; you can redistribute it and/or modify
029 * it under the terms of the GNU Lesser General Public License as
030 * published by the Free Software Foundation; either version 3 of the
031 * License, or (at your option) any later version. <br>
032 * <br>
033 * This library is distributed in the hope that it will be useful, but
034 * WITHOUT ANY WARRANTY; without even the implied warranty of
035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
036 * Lesser General Public License for more details. <br>
037 * <br>
038 * You should have received a copy of the GNU Lesser General Public
039 * License along with this library; if not see
040 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
041 */
042 public class ExamRoomSplit {
043 private ExamModel iModel = null;
044
045 /**
046 * Constructor
047 *
048 * @param model
049 * examination timetabling model
050 */
051 public ExamRoomSplit(ExamModel model) {
052 iModel = model;
053 }
054
055 /**
056 * generate report
057 */
058 public CSVFile report() {
059 CSVFile csv = new CSVFile();
060 csv.setHeader(new CSVField[] { new CSVField("Exam"), new CSVField("Enrl"), new CSVField("Period"),
061 new CSVField("Date"), new CSVField("Time"), new CSVField("Room 1"), new CSVField("Cap 1"),
062 new CSVField("Room 2"), new CSVField("Cap 2"), new CSVField("Room 3"), new CSVField("Cap 3"),
063 new CSVField("Room 4"), new CSVField("Cap 4") });
064 for (Exam exam : iModel.variables()) {
065 ExamPlacement placement = exam.getAssignment();
066 if (placement == null || placement.getRoomPlacements().size() <= 1)
067 continue;
068 List<CSVField> fields = new ArrayList<CSVField>();
069 fields.add(new CSVField(exam.getName()));
070 fields.add(new CSVField(exam.getStudents().size()));
071 fields.add(new CSVField(placement.getPeriod().getIndex() + 1));
072 fields.add(new CSVField(placement.getPeriod().getDayStr()));
073 fields.add(new CSVField(placement.getPeriod().getTimeStr()));
074 TreeSet<ExamRoomPlacement> rooms = new TreeSet<ExamRoomPlacement>(new ExamRoomComparator(exam, false));
075 rooms.addAll(placement.getRoomPlacements());
076 for (ExamRoomPlacement room : rooms) {
077 fields.add(new CSVField(room.getName()));
078 fields.add(new CSVField(room.getSize(exam.hasAltSeating())));
079 }
080 csv.addLine(fields);
081 }
082 return csv;
083 }
084 }