use of org.cpsolver.studentsct.model.Offering 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.Offering in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadLinkedSections.
/**
* Load linked sections
* @param constraintsEl constraints element
* @param offeringTable offering table
*/
protected void loadLinkedSections(Element constraintsEl, Map<Long, Offering> offeringTable) {
for (Iterator<?> i = constraintsEl.elementIterator("linked-sections"); i.hasNext(); ) {
Element linkedEl = (Element) i.next();
List<Section> sections = new ArrayList<Section>();
for (Iterator<?> j = linkedEl.elementIterator("section"); j.hasNext(); ) {
Element sectionEl = (Element) j.next();
Offering offering = offeringTable.get(Long.valueOf(sectionEl.attributeValue("offering")));
sections.add(offering.getSection(Long.valueOf(sectionEl.attributeValue("id"))));
}
getModel().addLinkedSections("true".equals(linkedEl.attributeValue("mustBeUsed", "false")), sections);
}
}
use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method load.
public void load(Document document) {
Element root = document.getRootElement();
if (getModel() != null && root.element("travel-times") != null)
loadTravelTimes(root.element("travel-times"), getModel().getDistanceMetric());
Progress.getInstance(getModel()).load(root, true);
Progress.getInstance(getModel()).message(Progress.MSGLEVEL_STAGE, "Restoring from backup ...");
Map<Long, Offering> offeringTable = new HashMap<Long, Offering>();
Map<Long, Course> courseTable = new HashMap<Long, Course>();
if (root.element("offerings") != null) {
loadOfferings(root.element("offerings"), offeringTable, courseTable, null);
}
List<Enrollment> bestEnrollments = new ArrayList<Enrollment>();
List<Enrollment> currentEnrollments = new ArrayList<Enrollment>();
if (root.element("students") != null) {
loadStudents(root.element("students"), offeringTable, courseTable, bestEnrollments, currentEnrollments);
}
if (root.element("constraints") != null)
loadLinkedSections(root.element("constraints"), offeringTable);
if (!bestEnrollments.isEmpty())
assignBest(bestEnrollments);
if (!currentEnrollments.isEmpty())
assignCurrent(currentEnrollments);
if (iMoveCriticalUp)
moveCriticalRequestsUp();
boolean hasFixed = false;
for (Request r : getModel().variables()) {
if (r instanceof CourseRequest && ((CourseRequest) r).isFixed()) {
hasFixed = true;
break;
}
}
if (hasFixed)
getModel().addGlobalConstraint(new FixedAssignments());
}
use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveOfferings.
/**
* Save offerings
* @param root document root
*/
protected void saveOfferings(Element root) {
Element offeringsEl = root.addElement("offerings");
for (Offering offering : getModel().getOfferings()) {
Element offeringEl = offeringsEl.addElement("offering");
saveOffering(offeringEl, offering);
saveReservations(offeringEl, offering);
saveRestrictions(offeringEl, offering);
}
}
use of org.cpsolver.studentsct.model.Offering in project cpsolver by UniTime.
the class StudentSectioningXMLSaver method saveLinkedSections.
/**
* Save linked sections
* @param root document root
*/
protected void saveLinkedSections(Element root) {
Element constrainstEl = root.addElement("constraints");
for (LinkedSections linkedSections : getModel().getLinkedSections()) {
Element linkEl = constrainstEl.addElement("linked-sections");
linkEl.addAttribute("mustBeUsed", linkedSections.isMustBeUsed() ? "true" : "false");
for (Offering offering : linkedSections.getOfferings()) for (Subpart subpart : linkedSections.getSubparts(offering)) for (Section section : linkedSections.getSections(subpart)) linkEl.addElement("section").addAttribute("offering", getId("offering", offering.getId())).addAttribute("id", getId("section", section.getId()));
}
}
Aggregations