001package net.sf.cpsolver.studentsct; 002 003import java.io.File; 004 005import net.sf.cpsolver.ifs.solution.Solution; 006import net.sf.cpsolver.ifs.solver.Solver; 007import net.sf.cpsolver.ifs.util.DataProperties; 008import net.sf.cpsolver.ifs.util.ToolBox; 009import net.sf.cpsolver.studentsct.model.Enrollment; 010import net.sf.cpsolver.studentsct.model.Request; 011import net.sf.cpsolver.studentsct.model.Student; 012 013/** 014 * A simple class that converts a solution (with real students) into an empty solution with 015 * expectations computed based on the assignments. It has two parameters, the input solution 016 * (XML file) and the output solution (also an XML file). 017 * <br> 018 * <br> 019 * 020 * @version StudentSct 1.2 (Student Sectioning)<br> 021 * Copyright (C) 2013 Tomáš Müller<br> 022 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 023 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 024 * <br> 025 * This library is free software; you can redistribute it and/or modify 026 * it under the terms of the GNU Lesser General Public License as 027 * published by the Free Software Foundation; either version 3 of the 028 * License, or (at your option) any later version. <br> 029 * <br> 030 * This library is distributed in the hope that it will be useful, but 031 * WITHOUT ANY WARRANTY; without even the implied warranty of 032 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 033 * Lesser General Public License for more details. <br> 034 * <br> 035 * You should have received a copy of the GNU Lesser General Public 036 * License along with this library; if not see 037 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 038 */ 039 040public class Solution2Expectations { 041 private static org.apache.log4j.Logger sLog = org.apache.log4j.Logger.getLogger(Solution2Expectations.class); 042 043 public static void main(String[] args) { 044 try { 045 ToolBox.configureLogging(); 046 047 DataProperties config = new DataProperties(); 048 049 String command = args[0]; 050 if ("real2exp".equals(command)) { 051 StudentSectioningModel model = new StudentSectioningModel(config); 052 StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model); 053 loader.setInputFile(new File(args[1])); 054 loader.load(); 055 056 sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 057 058 for (Student s: model.getStudents()) s.setDummy(true); 059 model.computeOnlineSectioningInfos(); 060 for (Student s: model.getStudents()) s.setDummy(false); 061 for (Request request: model.variables()) 062 if (request.getAssignment() != null) request.unassign(0); 063 064 Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, 0, 0); 065 Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config); 066 solver.setInitalSolution(solution); 067 new StudentSectioningXMLSaver(solver).save(new File(args[2])); 068 069 sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 070 } else if ("ll2exp".equals(command)) { 071 StudentSectioningModel model = new StudentSectioningModel(config); 072 StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model); 073 loader.setInputFile(new File(args[1])); 074 loader.load(); 075 076 sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 077 078 model.computeOnlineSectioningInfos(); 079 for (Request request: model.variables()) 080 if (request.getAssignment() != null) request.unassign(0); 081 082 Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, 0, 0); 083 Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config); 084 solver.setInitalSolution(solution); 085 new StudentSectioningXMLSaver(solver).save(new File(args[2])); 086 087 sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 088 } else if ("students".equals(command)) { 089 StudentSectioningModel model = new StudentSectioningModel(config); 090 StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model); 091 loader.setInputFile(new File(args[1])); 092 loader.setLoadStudents(false); 093 loader.load(); 094 095 sLog.info("Loaded [1]: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 096 097 StudentSectioningXMLLoader loder2 = new StudentSectioningXMLLoader(model); 098 loder2.setInputFile(new File(args[2])); 099 loder2.setLoadOfferings(false); 100 loder2.setLoadStudents(true); 101 loder2.load(); 102 103 sLog.info("Loaded [2]: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 104 105 Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, 0, 0); 106 Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config); 107 solver.setInitalSolution(solution); 108 new StudentSectioningXMLSaver(solver).save(new File(args[3])); 109 110 sLog.info("Saved [3]: " + ToolBox.dict2string(model.getExtendedInfo(), 2)); 111 } else { 112 sLog.error("Unknown command: " + command); 113 } 114 } catch (Exception e) { 115 sLog.error(e.getMessage(), e); 116 } 117 } 118 119}