use of org.cpsolver.studentsct.model.Course 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.Course 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