Search in sources :

Example 1 with Solution

use of org.cpsolver.ifs.solution.Solution in project cpsolver by UniTime.

the class SolutionEvaluator method main.

public static void main(String[] args) throws Exception {
    ToolBox.configureLogging();
    DataProperties properties = ToolBox.loadProperties(new java.io.File(args[0]));
    properties.putAll(System.getProperties());
    TimetableModel model = new TimetableModel(properties);
    Assignment<Lecture, Placement> assignment = new DefaultSingleAssignment<Lecture, Placement>();
    TimetableXMLLoader loader = new TimetableXMLLoader(model, assignment);
    loader.setInputFile(new File(args[1]));
    loader.load();
    Solution<Lecture, Placement> solution = new Solution<Lecture, Placement>(model, assignment);
    Test.saveOutputCSV(solution, new File(args[2]));
}
Also used : Lecture(org.cpsolver.coursett.model.Lecture) Placement(org.cpsolver.coursett.model.Placement) DataProperties(org.cpsolver.ifs.util.DataProperties) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) TimetableModel(org.cpsolver.coursett.model.TimetableModel) File(java.io.File) File(java.io.File) Solution(org.cpsolver.ifs.solution.Solution)

Example 2 with Solution

use of org.cpsolver.ifs.solution.Solution in project cpsolver by UniTime.

the class Test method load.

/** Load student sectioning model 
     * @param cfg solver configuration
     * @return loaded solution
     **/
public static Solution<Request, Enrollment> load(DataProperties cfg) {
    StudentSectioningModel model = null;
    Assignment<Request, Enrollment> assignment = null;
    try {
        if (cfg.getProperty("Test.CombineStudents") == null) {
            model = new StudentSectioningModel(cfg);
            assignment = new DefaultSingleAssignment<Request, Enrollment>();
            new StudentSectioningXMLLoader(model, assignment).load();
        } else {
            Solution<Request, Enrollment> solution = combineStudents(cfg, new File(cfg.getProperty("Test.CombineStudentsLastLike", cfg.getProperty("General.Input", "." + File.separator + "solution.xml"))), new File(cfg.getProperty("Test.CombineStudents")));
            model = (StudentSectioningModel) solution.getModel();
            assignment = solution.getAssignment();
        }
        if (cfg.getProperty("Test.ExtraStudents") != null) {
            StudentSectioningXMLLoader extra = new StudentSectioningXMLLoader(model, assignment);
            extra.setInputFile(new File(cfg.getProperty("Test.ExtraStudents")));
            extra.setLoadOfferings(false);
            extra.setLoadStudents(true);
            extra.setStudentFilter(new ExtraStudentFilter(model));
            extra.load();
        }
        if (cfg.getProperty("Test.LastLikeCourseDemands") != null)
            loadLastLikeCourseDemandsXml(model, new File(cfg.getProperty("Test.LastLikeCourseDemands")));
        if (cfg.getProperty("Test.StudentInfos") != null)
            loadStudentInfoXml(model, new File(cfg.getProperty("Test.StudentInfos")));
        if (cfg.getProperty("Test.CrsReq") != null)
            loadCrsReqFiles(model, cfg.getProperty("Test.CrsReq"));
    } catch (Exception e) {
        sLog.error("Unable to load model, reason: " + e.getMessage(), e);
        return null;
    }
    if (cfg.getPropertyBoolean("Debug.DistanceConflict", false))
        DistanceConflict.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.BranchBoundSelection", false))
        BranchBoundSelection.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.SwapStudentsSelection", false))
        SwapStudentSelection.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.TimeOverlaps", false))
        TimeOverlapsCounter.sDebug = true;
    if (cfg.getProperty("CourseRequest.SameTimePrecise") != null)
        CourseRequest.sSameTimePrecise = cfg.getPropertyBoolean("CourseRequest.SameTimePrecise", false);
    Logger.getLogger(BacktrackNeighbourSelection.class).setLevel(cfg.getPropertyBoolean("Debug.BacktrackNeighbourSelection", false) ? Level.DEBUG : Level.INFO);
    if (cfg.getPropertyBoolean("Test.FixPriorities", false))
        fixPriorities(model);
    return new Solution<Request, Enrollment>(model, assignment);
}
Also used : Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) File(java.io.File) IOException(java.io.IOException) Solution(org.cpsolver.ifs.solution.Solution) BacktrackNeighbourSelection(org.cpsolver.ifs.heuristics.BacktrackNeighbourSelection)

Example 3 with Solution

use of org.cpsolver.ifs.solution.Solution in project cpsolver by UniTime.

the class Solution2Expectations method main.

public static void main(String[] args) {
    try {
        ToolBox.configureLogging();
        DataProperties config = new DataProperties();
        String command = args[0];
        if ("real2exp".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.load();
            sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            for (Student s : model.getStudents()) s.setDummy(true);
            model.computeOnlineSectioningInfos(assignment);
            for (Student s : model.getStudents()) s.setDummy(false);
            for (Request request : model.variables()) assignment.unassign(0, request);
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[2]));
            sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else if ("ll2exp".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.load();
            sLog.info("Loaded: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            model.computeOnlineSectioningInfos(assignment);
            for (Request request : model.variables()) assignment.unassign(0, request);
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[2]));
            sLog.info("Saved: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else if ("students".equals(command)) {
            StudentSectioningModel model = new StudentSectioningModel(config);
            Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setInputFile(new File(args[1]));
            loader.setLoadStudents(false);
            loader.load();
            sLog.info("Loaded [1]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            StudentSectioningXMLLoader loder2 = new StudentSectioningXMLLoader(model, assignment);
            loder2.setInputFile(new File(args[2]));
            loder2.setLoadOfferings(false);
            loder2.setLoadStudents(true);
            loder2.load();
            sLog.info("Loaded [2]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
            Solution<Request, Enrollment> solution = new Solution<Request, Enrollment>(model, assignment, 0, 0);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(config);
            solver.setInitalSolution(solution);
            new StudentSectioningXMLSaver(solver).save(new File(args[3]));
            sLog.info("Saved [3]: " + ToolBox.dict2string(model.getExtendedInfo(assignment), 2));
        } else {
            sLog.error("Unknown command: " + command);
        }
    } catch (Exception e) {
        sLog.error(e.getMessage(), e);
    }
}
Also used : Solver(org.cpsolver.ifs.solver.Solver) DataProperties(org.cpsolver.ifs.util.DataProperties) Request(org.cpsolver.studentsct.model.Request) Student(org.cpsolver.studentsct.model.Student) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) Assignment(org.cpsolver.ifs.assignment.Assignment) Enrollment(org.cpsolver.studentsct.model.Enrollment) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File) Solution(org.cpsolver.ifs.solution.Solution)

Aggregations

File (java.io.File)3 Solution (org.cpsolver.ifs.solution.Solution)3 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)2 DataProperties (org.cpsolver.ifs.util.DataProperties)2 Enrollment (org.cpsolver.studentsct.model.Enrollment)2 Request (org.cpsolver.studentsct.model.Request)2 IOException (java.io.IOException)1 Lecture (org.cpsolver.coursett.model.Lecture)1 Placement (org.cpsolver.coursett.model.Placement)1 TimetableModel (org.cpsolver.coursett.model.TimetableModel)1 Assignment (org.cpsolver.ifs.assignment.Assignment)1 BacktrackNeighbourSelection (org.cpsolver.ifs.heuristics.BacktrackNeighbourSelection)1 Solver (org.cpsolver.ifs.solver.Solver)1 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)1 Student (org.cpsolver.studentsct.model.Student)1