use of org.cpsolver.studentsct.reservation.CurriculumReservation in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadReservation.
/**
* Load reservation
* @param reservationEl reservation element
* @param offering parent offering
* @param configTable config table (of the offering)
* @param sectionTable section table (of the offering)
* @return loaded reservation
*/
protected Reservation loadReservation(Element reservationEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
Reservation r = null;
if ("individual".equals(reservationEl.attributeValue("type"))) {
Set<Long> studentIds = new HashSet<Long>();
for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
Element studentEl = (Element) k.next();
studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
}
r = new IndividualReservation(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
} else if ("group".equals(reservationEl.attributeValue("type"))) {
Set<Long> studentIds = new HashSet<Long>();
for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
Element studentEl = (Element) k.next();
studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
}
r = new GroupReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, studentIds);
} else if ("lc".equals(reservationEl.attributeValue("type"))) {
Set<Long> studentIds = new HashSet<Long>();
for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
Element studentEl = (Element) k.next();
studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
}
long courseId = Long.parseLong(reservationEl.attributeValue("course"));
for (Course course : offering.getCourses()) {
if (course.getId() == courseId)
r = new LearningCommunityReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), course, studentIds);
}
} else if ("curriculum".equals(reservationEl.attributeValue("type")) || "curriculum-override".equals(reservationEl.attributeValue("type"))) {
List<String> acadAreas = new ArrayList<String>();
for (Iterator<?> k = reservationEl.elementIterator("area"); k.hasNext(); ) {
Element areaEl = (Element) k.next();
acadAreas.add(areaEl.attributeValue("code"));
}
if (acadAreas.isEmpty() && reservationEl.attributeValue("area") != null)
acadAreas.add(reservationEl.attributeValue("area"));
List<String> classifications = new ArrayList<String>();
for (Iterator<?> k = reservationEl.elementIterator("classification"); k.hasNext(); ) {
Element clasfEl = (Element) k.next();
classifications.add(clasfEl.attributeValue("code"));
}
List<String> majors = new ArrayList<String>();
for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
Element majorEl = (Element) k.next();
majors.add(majorEl.attributeValue("code"));
}
List<String> minors = new ArrayList<String>();
for (Iterator<?> k = reservationEl.elementIterator("minor"); k.hasNext(); ) {
Element minorEl = (Element) k.next();
minors.add(minorEl.attributeValue("code"));
}
if ("curriculum".equals(reservationEl.attributeValue("type")))
r = new CurriculumReservation(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, acadAreas, classifications, majors, minors);
else
r = new CurriculumOverride(Long.valueOf(reservationEl.attributeValue("id")), Double.parseDouble(reservationEl.attributeValue("limit", "-1")), offering, acadAreas, classifications, majors, minors);
for (Iterator<?> k = reservationEl.elementIterator("major"); k.hasNext(); ) {
Element majorEl = (Element) k.next();
for (Iterator<?> l = majorEl.elementIterator("concentration"); l.hasNext(); ) {
Element concentrationEl = (Element) l.next();
((CurriculumReservation) r).addConcentration(majorEl.attributeValue("code"), concentrationEl.attributeValue("code"));
}
}
} else if ("course".equals(reservationEl.attributeValue("type"))) {
long courseId = Long.parseLong(reservationEl.attributeValue("course"));
for (Course course : offering.getCourses()) {
if (course.getId() == courseId)
r = new CourseReservation(Long.valueOf(reservationEl.attributeValue("id")), course);
}
} else if ("dummy".equals(reservationEl.attributeValue("type"))) {
r = new DummyReservation(offering);
} else if ("override".equals(reservationEl.attributeValue("type"))) {
Set<Long> studentIds = new HashSet<Long>();
for (Iterator<?> k = reservationEl.elementIterator("student"); k.hasNext(); ) {
Element studentEl = (Element) k.next();
studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
}
r = new ReservationOverride(Long.valueOf(reservationEl.attributeValue("id")), offering, studentIds);
}
if (r == null) {
sLogger.error("Unknown reservation type " + reservationEl.attributeValue("type"));
return null;
}
r.setExpired("true".equals(reservationEl.attributeValue("expired", "false")));
for (Iterator<?> k = reservationEl.elementIterator("config"); k.hasNext(); ) {
Element configEl = (Element) k.next();
r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
}
for (Iterator<?> k = reservationEl.elementIterator("section"); k.hasNext(); ) {
Element sectionEl = (Element) k.next();
r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))), false);
}
r.setPriority(Integer.parseInt(reservationEl.attributeValue("priority", String.valueOf(r.getPriority()))));
r.setMustBeUsed("true".equals(reservationEl.attributeValue("mustBeUsed", r.mustBeUsed() ? "true" : "false")));
r.setAllowOverlap("true".equals(reservationEl.attributeValue("allowOverlap", r.isAllowOverlap() ? "true" : "false")));
r.setCanAssignOverLimit("true".equals(reservationEl.attributeValue("canAssignOverLimit", r.canAssignOverLimit() ? "true" : "false")));
r.setAllowDisabled("true".equals(reservationEl.attributeValue("allowDisabled", r.isAllowDisabled() ? "true" : "false")));
r.setNeverIncluded("true".equals(reservationEl.attributeValue("neverIncluded", "false")));
r.setBreakLinkedSections("true".equals(reservationEl.attributeValue("breakLinkedSections", "false")));
return r;
}
use of org.cpsolver.studentsct.reservation.CurriculumReservation 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()));
}
}
}
Aggregations