use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class SectionLimitCheck method check.
/**
* Check for sections that have more students enrolled than it is allowed,
* i.e., the sum of requests weights is above the section limit
* @param assignment current assignment
* @return false, if there is such a case
*/
public boolean check(Assignment<Request, Enrollment> assignment) {
sLog.info("Checking section limits...");
boolean ret = true;
for (Offering offering : getModel().getOfferings()) {
for (Config config : offering.getConfigs()) {
for (Subpart subpart : config.getSubparts()) {
for (Section section : subpart.getSections()) {
if (section.getLimit() < 0)
continue;
double used = section.getEnrollmentWeight(assignment, null);
if (used - section.getMaxEnrollmentWeight(assignment) > section.getLimit()) {
sLog.error("Section " + section.getName() + " exceeds its limit " + sDF.format(used) + ">" + section.getLimit() + " for more than one student (W:" + section.getMaxEnrollmentWeight(assignment) + ")");
ret = false;
} else if (Math.round(used) > section.getLimit()) {
sLog.debug("Section " + section.getName() + " exceeds its limit " + sDF.format(used) + ">" + section.getLimit() + " for less than one student (W:" + section.getMaxEnrollmentWeight(assignment) + ")");
}
}
}
}
}
return ret;
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentSectioningModel method clearOnlineSectioningInfos.
/**
* Empty online student sectioning infos for all sections (see
* {@link Section#getSpaceExpected()} and {@link Section#getSpaceHeld()}).
*/
public void clearOnlineSectioningInfos() {
for (Offering offering : iOfferings) {
for (Config config : offering.getConfigs()) {
for (Subpart subpart : config.getSubparts()) {
for (Section section : subpart.getSections()) {
section.setSpaceExpected(0);
section.setSpaceHeld(0);
}
}
}
}
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadOfferings.
/**
* Load offerings
* @param offeringsEl offerings element
* @param offeringTable offering table
* @param courseTable course table
* @param timetable provided timetable (null if to be loaded from the given document)
*/
protected void loadOfferings(Element offeringsEl, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable, Map<Long, Placement> timetable) {
HashMap<Long, Config> configTable = new HashMap<Long, Config>();
HashMap<Long, Subpart> subpartTable = new HashMap<Long, Subpart>();
HashMap<Long, Section> sectionTable = new HashMap<Long, Section>();
for (Iterator<?> i = offeringsEl.elementIterator("offering"); i.hasNext(); ) {
Element offeringEl = (Element) i.next();
Offering offering = new Offering(Long.parseLong(offeringEl.attributeValue("id")), offeringEl.attributeValue("name", "O" + offeringEl.attributeValue("id")));
offeringTable.put(Long.valueOf(offering.getId()), offering);
getModel().addOffering(offering);
for (Iterator<?> j = offeringEl.elementIterator("course"); j.hasNext(); ) {
Element courseEl = (Element) j.next();
Course course = loadCourse(courseEl, offering);
courseTable.put(Long.valueOf(course.getId()), course);
}
for (Iterator<?> j = offeringEl.elementIterator("config"); j.hasNext(); ) {
Element configEl = (Element) j.next();
Config config = loadConfig(configEl, offering, subpartTable, sectionTable, timetable);
configTable.put(config.getId(), config);
}
for (Iterator<?> j = offeringEl.elementIterator("reservation"); j.hasNext(); ) {
Element reservationEl = (Element) j.next();
loadReservation(reservationEl, offering, configTable, sectionTable);
}
for (Iterator<?> j = offeringEl.elementIterator("restriction"); j.hasNext(); ) {
Element restrictionEl = (Element) j.next();
loadRestriction(restrictionEl, offering, configTable, sectionTable);
}
}
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveReservation.
/**
* Save reservation
* @param reservationEl reservation element to be populated
* @param reservation reservation to be saved
*/
protected void saveReservation(Element reservationEl, Reservation reservation) {
reservationEl.addAttribute("id", getId("reservation", reservation.getId()));
reservationEl.addAttribute("expired", reservation.isExpired() ? "true" : "false");
if (reservation instanceof LearningCommunityReservation) {
LearningCommunityReservation lc = (LearningCommunityReservation) reservation;
reservationEl.addAttribute("type", "lc");
for (Long studentId : lc.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
if (lc.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(lc.getReservationLimit()));
reservationEl.addAttribute("course", getId("course", lc.getCourse().getId()));
} else if (reservation instanceof GroupReservation) {
GroupReservation gr = (GroupReservation) reservation;
reservationEl.addAttribute("type", "group");
for (Long studentId : gr.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
if (gr.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(gr.getReservationLimit()));
} else if (reservation instanceof ReservationOverride) {
reservationEl.addAttribute("type", "override");
ReservationOverride o = (ReservationOverride) reservation;
for (Long studentId : o.getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
} else if (reservation instanceof IndividualReservation) {
reservationEl.addAttribute("type", "individual");
for (Long studentId : ((IndividualReservation) reservation).getStudentIds()) reservationEl.addElement("student").addAttribute("id", getId("student", studentId));
} else if (reservation instanceof CurriculumReservation) {
reservationEl.addAttribute("type", (reservation instanceof CurriculumOverride ? "curriculum-override" : "curriculum"));
CurriculumReservation cr = (CurriculumReservation) reservation;
if (cr.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
if (cr.getAcademicAreas().size() == 1)
reservationEl.addAttribute("area", cr.getAcademicAreas().iterator().next());
else {
for (String area : cr.getAcademicAreas()) reservationEl.addElement("area").addAttribute("code", area);
}
for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
for (String major : cr.getMajors()) {
Element majorEl = reservationEl.addElement("major").addAttribute("code", major);
Set<String> concentrations = cr.getConcentrations(major);
if (concentrations != null)
for (String conc : concentrations) majorEl.addElement("concentration").addAttribute("code", conc);
}
for (String minor : cr.getMinors()) reservationEl.addElement("minor").addAttribute("code", minor);
} else if (reservation instanceof CourseReservation) {
reservationEl.addAttribute("type", "course");
CourseReservation cr = (CourseReservation) reservation;
reservationEl.addAttribute("course", getId("course", cr.getCourse().getId()));
} else if (reservation instanceof DummyReservation) {
reservationEl.addAttribute("type", "dummy");
}
reservationEl.addAttribute("priority", String.valueOf(reservation.getPriority()));
reservationEl.addAttribute("mustBeUsed", reservation.mustBeUsed() ? "true" : "false");
reservationEl.addAttribute("allowOverlap", reservation.isAllowOverlap() ? "true" : "false");
reservationEl.addAttribute("canAssignOverLimit", reservation.canAssignOverLimit() ? "true" : "false");
reservationEl.addAttribute("allowDisabled", reservation.isAllowDisabled() ? "true" : "false");
if (reservation.neverIncluded())
reservationEl.addAttribute("neverIncluded", "true");
if (reservation.canBreakLinkedSections())
reservationEl.addAttribute("breakLinkedSections", "true");
for (Config config : reservation.getConfigs()) reservationEl.addElement("config").addAttribute("id", getId("config", config.getId()));
for (Map.Entry<Subpart, Set<Section>> entry : reservation.getSections().entrySet()) {
for (Section section : entry.getValue()) {
reservationEl.addElement("section").addAttribute("id", getId("section", section.getId()));
}
}
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveOffering.
/**
* Save given offering
* @param offeringEl offering element to be populated
* @param offering offering to be saved
*/
protected void saveOffering(Element offeringEl, Offering offering) {
offeringEl.addAttribute("id", getId("offering", offering.getId()));
if (iShowNames)
offeringEl.addAttribute("name", offering.getName());
for (Course course : offering.getCourses()) {
Element courseEl = offeringEl.addElement("course");
saveCourse(courseEl, course);
}
for (Config config : offering.getConfigs()) {
Element configEl = offeringEl.addElement("config");
saveConfig(configEl, config);
}
}
Aggregations