001 package net.sf.cpsolver.exam.reports; 002 003 import java.util.Enumeration; 004 import java.util.Iterator; 005 import java.util.TreeSet; 006 import java.util.Vector; 007 008 import net.sf.cpsolver.exam.model.Exam; 009 import net.sf.cpsolver.exam.model.ExamModel; 010 import net.sf.cpsolver.exam.model.ExamPlacement; 011 import net.sf.cpsolver.exam.model.ExamRoomPlacement; 012 import net.sf.cpsolver.ifs.util.CSVFile; 013 import net.sf.cpsolver.ifs.util.CSVFile.CSVField; 014 015 /** 016 * Export room splitting into a CSV file. 017 * <br><br> 018 * Usage:<br> 019 * <code> 020 * new ExamRoomSplit(model).report().save(file); 021 * </code> 022 * <br><br> 023 * 024 * @version 025 * ExamTT 1.1 (Examination Timetabling)<br> 026 * Copyright (C) 2007 Tomáš Müller<br> 027 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 028 * Lazenska 391, 76314 Zlin, Czech Republic<br> 029 * <br> 030 * This library is free software; you can redistribute it and/or 031 * modify it under the terms of the GNU Lesser General Public 032 * License as published by the Free Software Foundation; either 033 * version 2.1 of the License, or (at your option) any later version. 034 * <br><br> 035 * This library is distributed in the hope that it will be useful, 036 * but WITHOUT ANY WARRANTY; without even the implied warranty of 037 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 038 * Lesser General Public License for more details. 039 * <br><br> 040 * You should have received a copy of the GNU Lesser General Public 041 * License along with this library; if not, write to the Free Software 042 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 043 */ 044 public class ExamRoomSplit { 045 private ExamModel iModel = null; 046 047 /** 048 * Constructor 049 * @param model 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[] { 061 new CSVField("Exam"), 062 new CSVField("Enrl"), 063 new CSVField("Period"), 064 new CSVField("Date"), 065 new CSVField("Time"), 066 new CSVField("Room 1"), 067 new CSVField("Cap 1"), 068 new CSVField("Room 2"), 069 new CSVField("Cap 2"), 070 new CSVField("Room 3"), 071 new CSVField("Cap 3"), 072 new CSVField("Room 4"), 073 new CSVField("Cap 4") 074 }); 075 for (Enumeration e=iModel.variables().elements();e.hasMoreElements();) { 076 Exam exam = (Exam)e.nextElement(); 077 ExamPlacement placement = (ExamPlacement)exam.getAssignment(); 078 if (placement==null || placement.getRoomPlacements().size()<=1) continue; 079 Vector fields = new Vector(); 080 fields.add(new CSVField(exam.getName())); 081 fields.add(new CSVField(exam.getStudents().size())); 082 fields.add(new CSVField(placement.getPeriod().getIndex()+1)); 083 fields.add(new CSVField(placement.getPeriod().getDayStr())); 084 fields.add(new CSVField(placement.getPeriod().getTimeStr())); 085 TreeSet rooms = new TreeSet(new ExamRoomComparator(exam,false)); 086 rooms.addAll(placement.getRoomPlacements()); 087 for (Iterator i=rooms.iterator();i.hasNext();) { 088 ExamRoomPlacement room = (ExamRoomPlacement)i.next(); 089 fields.add(new CSVField(room.getName())); 090 fields.add(new CSVField(room.getSize(exam.hasAltSeating()))); 091 } 092 csv.addLine(fields); 093 } 094 return csv; 095 } 096 }