001    package net.sf.cpsolver.studentsct;
002    
003    import java.io.File;
004    
005    import net.sf.cpsolver.ifs.solution.Solution;
006    import net.sf.cpsolver.ifs.solver.Solver;
007    import net.sf.cpsolver.ifs.util.DataProperties;
008    import net.sf.cpsolver.ifs.util.ToolBox;
009    import net.sf.cpsolver.studentsct.model.Enrollment;
010    import net.sf.cpsolver.studentsct.model.Request;
011    import 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 Tomas Muller<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    
040    public 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                StudentSectioningModel model = new StudentSectioningModel(config);
050                StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model);
051                loader.setInputFile(new File(args[0]));
052                loader.load();
053                
054                sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(), 2));
055                
056                for (Student s: model.getStudents()) s.setDummy(true);
057                model.computeOnlineSectioningInfos();
058                for (Student s: model.getStudents()) s.setDummy(false);
059                for (Request request: model.variables())
060                    if (request.getAssignment() != null) request.unassign(0);
061                
062                Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, 0, 0);
063                Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
064                solver.setInitalSolution(solution);
065                new StudentSectioningXMLSaver(solver).save(new File(args[1]));
066                
067                sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(), 2));
068                
069            } catch (Exception e) {
070                sLog.error(e.getMessage(), e);
071            }
072        }
073    
074    }