use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class MultiCriteriaBranchAndBoundSelection method backTrack.
/** branch & bound search */
public void backTrack(int idx) {
if (iTimeout > 0 && (JProf.currentTimeMillis() - iT0) > iTimeout) {
iTimeoutReached = true;
return;
}
if (idx == iCurrentAssignment.length) {
if (iBestAssignment == null || iComparator.compare(iAssignment, iCurrentAssignment, iBestAssignment) < 0)
saveBest();
return;
} else if (iBestAssignment != null && !iComparator.canImprove(iAssignment, idx, iCurrentAssignment, iBestAssignment)) {
return;
}
Request request = iStudent.getRequests().get(idx);
if (!canAssign(request, idx)) {
backTrack(idx + 1);
return;
}
List<Enrollment> values = null;
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
if (!courseRequest.getSelectedChoices().isEmpty()) {
values = courseRequest.getSelectedEnrollments(iAssignment, true);
if (values != null && !values.isEmpty()) {
boolean hasNoConflictValue = false;
for (Enrollment enrollment : values) {
if (inConflict(idx, enrollment))
continue;
hasNoConflictValue = true;
iCurrentAssignment[idx] = enrollment;
backTrack(idx + 1);
iCurrentAssignment[idx] = null;
}
if (hasNoConflictValue && iBranchWhenSelectedHasNoConflict)
return;
}
}
values = iValues.get(courseRequest);
if (values == null) {
values = values(courseRequest);
iValues.put(courseRequest, values);
}
} else {
values = request.computeEnrollments(iAssignment);
}
boolean hasNoConflictValue = false;
for (Enrollment enrollment : values) {
if (inConflict(idx, enrollment))
continue;
hasNoConflictValue = true;
iCurrentAssignment[idx] = enrollment;
backTrack(idx + 1);
iCurrentAssignment[idx] = null;
}
if (canLeaveUnassigned(request) || (!hasNoConflictValue && request instanceof CourseRequest))
backTrack(idx + 1);
}
use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class MultiCriteriaBranchAndBoundSelection method setRequiredSections.
@Override
public void setRequiredSections(Hashtable<CourseRequest, Set<Section>> requiredSections) {
if (requiredSections != null) {
for (Map.Entry<CourseRequest, Set<Section>> entry : requiredSections.entrySet()) {
Hashtable<Subpart, Section> subSection = new Hashtable<Subpart, Section>();
iRequiredSection.put(entry.getKey(), subSection);
for (Section section : entry.getValue()) {
if (subSection.isEmpty())
iRequiredConfig.put(entry.getKey(), section.getSubpart().getConfig());
subSection.put(section.getSubpart(), section);
}
}
}
}
use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class StudentPreferencePenalties method setPenalties.
/**
* Set the computed penalties to all sections of all requests of the given
* student
* @param student given student
* @param distributionType penalty distribution type
*/
public static void setPenalties(Student student, int distributionType) {
if (sDebug)
sLog.debug("Setting penalties for " + student);
StudentPreferencePenalties penalties = new StudentPreferencePenalties(distributionType);
for (Request request : student.getRequests()) {
if (!(request instanceof CourseRequest))
continue;
CourseRequest courseRequest = (CourseRequest) request;
if (sDebug)
sLog.debug("-- " + courseRequest);
for (Course course : courseRequest.getCourses()) {
if (sDebug)
sLog.debug(" -- " + course.getName());
for (Config config : course.getOffering().getConfigs()) {
if (sDebug)
sLog.debug(" -- " + config.getName());
for (Subpart subpart : config.getSubparts()) {
if (sDebug)
sLog.debug(" -- " + subpart.getName());
for (Section section : subpart.getSections()) {
section.setPenalty(penalties.getPenalty(section));
if (sDebug)
sLog.debug(" -- " + section);
}
}
}
}
courseRequest.clearCache();
}
}
use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class StudentSctBBTest method getMessages.
/**
* Return a list of messages ({@link Message} objects) from the sectioning
* of the given student
* @return enrollment messages
*/
public List<Message> getMessages() {
Assignment<Request, Enrollment> assignment = getSolution().getAssignment();
List<Message> ret = new ArrayList<Message>();
ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Solution found in " + iTime + " ms."));
if (iTimeoutReached)
ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Time out reached, solution optimality can not be guaranteed."));
for (Request request : getStudent().getRequests()) {
if (!request.isAlternative() && assignment.getValue(request) == null) {
ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll to " + request + ", " + (request instanceof CourseRequest ? ((CourseRequest) request).getCourses().size() == 1 ? "course is" : "courses are" : "time is") + " not available."));
Collection<Enrollment> values = (request instanceof CourseRequest ? (Collection<Enrollment>) ((CourseRequest) request).getAvaiableEnrollmentsSkipSameTime(assignment) : request.computeEnrollments(assignment));
for (Iterator<Enrollment> f = values.iterator(); f.hasNext(); ) {
Enrollment enrollment = f.next();
Set<Enrollment> conf = conflictValues(assignment, enrollment);
if (conf != null && !conf.isEmpty()) {
Enrollment conflict = conf.iterator().next();
if (conflict.equals(enrollment))
ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br> ") + "<br> is not available."));
else
ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br> ") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br> ") + "</ul>"));
}
}
}
if (request instanceof CourseRequest && assignment.getValue(request) != null) {
CourseRequest courseRequest = (CourseRequest) request;
Enrollment enrollment = assignment.getValue(request);
List<Enrollment> selectedEnrollments = courseRequest.getSelectedEnrollments(assignment, false);
if (selectedEnrollments != null && !selectedEnrollments.isEmpty() && !selectedEnrollments.contains(enrollment)) {
Course course = (courseRequest.getSelectedChoices().iterator().next()).getOffering().getCourse(getStudent());
Enrollment selected = selectedEnrollments.get(0);
Set<Enrollment> conf = conflictValues(assignment, selected);
if (conf != null && !conf.isEmpty()) {
ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + ", seleted " + (courseRequest.getSelectedChoices().size() == 1 ? "class is" : "classes are") + " conflicting with other choices."));
Enrollment conflict = conf.iterator().next();
if (conflict.equals(selected))
ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br> ") + "<br> is not available."));
else
ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br> ") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br> ") + "</ul>"));
} else {
ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + "."));
}
}
}
}
return ret;
}
Aggregations