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