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]));
}
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);
}
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);
}
}
Aggregations