use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class Test method fixWeights.
private static void fixWeights(StudentSectioningModel model) {
HashMap<Course, Integer> lastLike = new HashMap<Course, Integer>();
HashMap<Course, Integer> real = new HashMap<Course, Integer>();
HashSet<Long> lastLikeIds = new HashSet<Long>();
HashSet<Long> realIds = new HashSet<Long>();
for (Student student : model.getStudents()) {
if (student.isDummy()) {
if (!lastLikeIds.add(new Long(student.getId()))) {
sLog.error("Two last-like student with id " + student.getId());
}
} else {
if (!realIds.add(new Long(student.getId()))) {
sLog.error("Two real student with id " + student.getId());
}
}
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
Course course = courseRequest.getCourses().get(0);
Integer cnt = (student.isDummy() ? lastLike : real).get(course);
(student.isDummy() ? lastLike : real).put(course, new Integer((cnt == null ? 0 : cnt.intValue()) + 1));
}
}
}
for (Student student : new ArrayList<Student>(model.getStudents())) {
if (student.isDummy() && realIds.contains(new Long(student.getId()))) {
sLog.warn("There is both last-like and real student with id " + student.getId());
long newId = -1;
while (true) {
newId = 1 + (long) (999999999L * Math.random());
if (!realIds.contains(new Long(newId)) && !lastLikeIds.contains(new Long(newId)))
break;
}
lastLikeIds.remove(new Long(student.getId()));
lastLikeIds.add(new Long(newId));
student.setId(newId);
sLog.warn(" -- last-like student id changed to " + student.getId());
}
for (Request request : new ArrayList<Request>(student.getRequests())) {
if (!student.isDummy()) {
request.setWeight(1.0);
continue;
}
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
Course course = courseRequest.getCourses().get(0);
Integer lastLikeCnt = lastLike.get(course);
Integer realCnt = real.get(course);
courseRequest.setWeight(getLastLikeStudentWeight(course, realCnt == null ? 0 : realCnt.intValue(), lastLikeCnt == null ? 0 : lastLikeCnt.intValue()));
} else
request.setWeight(1.0);
if (request.getWeight() <= 0.0) {
model.removeVariable(request);
student.getRequests().remove(request);
}
}
if (student.getRequests().isEmpty()) {
model.getStudents().remove(student);
}
}
}
use of org.cpsolver.studentsct.model.Request 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.studentsct.model.Request in project cpsolver by UniTime.
the class StudentSectioningModel method removeStudent.
/**
* Remove a student from the model
* @param student a student to be removed from the problem
*/
public void removeStudent(Student student) {
iStudents.remove(student);
if (student.isDummy())
iNrDummyStudents--;
StudentConflict conflict = null;
for (Request request : student.getRequests()) {
for (Constraint<Request, Enrollment> c : request.constraints()) {
if (c instanceof StudentConflict) {
conflict = (StudentConflict) c;
break;
}
}
if (conflict != null)
conflict.removeVariable(request);
removeVariable(request);
}
if (conflict != null)
removeConstraint(conflict);
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class OverlapCheck method check.
/**
* Check for overlapping sections that are attended by the same student
* @param a current assignment
* @return false, if there is such a case
*/
public boolean check(Assignment<Request, Enrollment> a) {
sLog.info("Checking for overlaps...");
boolean ret = true;
for (Student student : getModel().getStudents()) {
HashMap<TimeLocation, SctAssignment> times = new HashMap<TimeLocation, SctAssignment>();
for (Request request : student.getRequests()) {
Enrollment enrollment = a.getValue(request);
if (enrollment == null)
continue;
for (SctAssignment assignment : enrollment.getAssignments()) {
if (assignment.getTime() == null)
continue;
for (TimeLocation time : times.keySet()) {
if (time.hasIntersection(assignment.getTime())) {
sLog.error("Student " + student + " assignment " + assignment + " overlaps with " + times.get(time));
ret = false;
}
}
times.put(assignment.getTime(), assignment);
}
}
}
return ret;
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class LinkedSections method createConstraint.
/**
* Create linked-section constraints for a given student
*/
private LinkedSectionsConstraint createConstraint(Student student) {
List<Request> requests = new ArrayList<Request>();
int nrOfferings = 0;
requests: for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
for (Course course : ((CourseRequest) request).getCourses()) {
Map<Subpart, Set<Section>> subpartsThisOffering = iSections.get(course.getOffering());
if (subpartsThisOffering != null) {
requests.add(request);
nrOfferings++;
continue requests;
}
}
}
}
if (nrOfferings <= 1)
return null;
LinkedSectionsConstraint constraint = new LinkedSectionsConstraint(student, requests);
student.getRequests().get(0).getModel().addConstraint(constraint);
return constraint;
}
Aggregations