use of org.cpsolver.studentsct.reservation.CurriculumRestriction in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadRestriction.
/**
* Load restriction
* @param restrictionEl restriction element
* @param offering parent offering
* @param configTable config table (of the offering)
* @param sectionTable section table (of the offering)
* @return loaded restriction
*/
protected Restriction loadRestriction(Element restrictionEl, Offering offering, HashMap<Long, Config> configTable, HashMap<Long, Section> sectionTable) {
Restriction r = null;
if ("individual".equals(restrictionEl.attributeValue("type"))) {
Set<Long> studentIds = new HashSet<Long>();
for (Iterator<?> k = restrictionEl.elementIterator("student"); k.hasNext(); ) {
Element studentEl = (Element) k.next();
studentIds.add(Long.parseLong(studentEl.attributeValue("id")));
}
r = new IndividualRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, studentIds);
} else if ("curriculum".equals(restrictionEl.attributeValue("type"))) {
List<String> acadAreas = new ArrayList<String>();
for (Iterator<?> k = restrictionEl.elementIterator("area"); k.hasNext(); ) {
Element areaEl = (Element) k.next();
acadAreas.add(areaEl.attributeValue("code"));
}
if (acadAreas.isEmpty() && restrictionEl.attributeValue("area") != null)
acadAreas.add(restrictionEl.attributeValue("area"));
List<String> classifications = new ArrayList<String>();
for (Iterator<?> k = restrictionEl.elementIterator("classification"); k.hasNext(); ) {
Element clasfEl = (Element) k.next();
classifications.add(clasfEl.attributeValue("code"));
}
List<String> majors = new ArrayList<String>();
for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
Element majorEl = (Element) k.next();
majors.add(majorEl.attributeValue("code"));
}
List<String> minors = new ArrayList<String>();
for (Iterator<?> k = restrictionEl.elementIterator("minor"); k.hasNext(); ) {
Element minorEl = (Element) k.next();
minors.add(minorEl.attributeValue("code"));
}
r = new CurriculumRestriction(Long.valueOf(restrictionEl.attributeValue("id")), offering, acadAreas, classifications, majors, minors);
for (Iterator<?> k = restrictionEl.elementIterator("major"); k.hasNext(); ) {
Element majorEl = (Element) k.next();
for (Iterator<?> l = majorEl.elementIterator("concentration"); l.hasNext(); ) {
Element concentrationEl = (Element) l.next();
((CurriculumRestriction) r).addConcentration(majorEl.attributeValue("code"), concentrationEl.attributeValue("code"));
}
}
} else if ("course".equals(restrictionEl.attributeValue("type"))) {
long courseId = Long.parseLong(restrictionEl.attributeValue("course"));
for (Course course : offering.getCourses()) {
if (course.getId() == courseId)
r = new CourseRestriction(Long.valueOf(restrictionEl.attributeValue("id")), course);
}
}
if (r == null) {
sLogger.error("Unknown reservation type " + restrictionEl.attributeValue("type"));
return null;
}
for (Iterator<?> k = restrictionEl.elementIterator("config"); k.hasNext(); ) {
Element configEl = (Element) k.next();
r.addConfig(configTable.get(Long.parseLong(configEl.attributeValue("id"))));
}
for (Iterator<?> k = restrictionEl.elementIterator("section"); k.hasNext(); ) {
Element sectionEl = (Element) k.next();
r.addSection(sectionTable.get(Long.parseLong(sectionEl.attributeValue("id"))));
}
return r;
}
use of org.cpsolver.studentsct.reservation.CurriculumRestriction in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveRestriction.
/**
* Save restriction
* @param restrictionEl restriction element to be populated
* @param restriction restriction to be saved
*/
protected void saveRestriction(Element restrictionEl, Restriction restriction) {
restrictionEl.addAttribute("id", getId("restriction", restriction.getId()));
if (restriction instanceof IndividualRestriction) {
restrictionEl.addAttribute("type", "individual");
for (Long studentId : ((IndividualRestriction) restriction).getStudentIds()) restrictionEl.addElement("student").addAttribute("id", getId("student", studentId));
} else if (restriction instanceof CurriculumRestriction) {
restrictionEl.addAttribute("type", "curriculum");
CurriculumRestriction cr = (CurriculumRestriction) restriction;
if (cr.getAcademicAreas().size() == 1)
restrictionEl.addAttribute("area", cr.getAcademicAreas().iterator().next());
else {
for (String area : cr.getAcademicAreas()) restrictionEl.addElement("area").addAttribute("code", area);
}
for (String clasf : cr.getClassifications()) restrictionEl.addElement("classification").addAttribute("code", clasf);
for (String major : cr.getMajors()) {
Element majorEl = restrictionEl.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()) restrictionEl.addElement("minor").addAttribute("code", minor);
} else if (restriction instanceof CourseRestriction) {
restrictionEl.addAttribute("type", "course");
CourseRestriction cr = (CourseRestriction) restriction;
restrictionEl.addAttribute("course", getId("course", cr.getCourse().getId()));
}
for (Config config : restriction.getConfigs()) restrictionEl.addElement("config").addAttribute("id", getId("config", config.getId()));
for (Map.Entry<Subpart, Set<Section>> entry : restriction.getSections().entrySet()) {
for (Section section : entry.getValue()) {
restrictionEl.addElement("section").addAttribute("id", getId("section", section.getId()));
}
}
}
Aggregations