use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadSection.
/**
* Load section
* @param sectionEl section element
* @param subpart parent subpart
* @param sectionTable section table (of the offering)
* @param timetable provided timetable
* @return loaded section
*/
@SuppressWarnings("deprecation")
protected Section loadSection(Element sectionEl, Subpart subpart, Map<Long, Section> sectionTable, Map<Long, Placement> timetable) {
Section parentSection = null;
if (sectionEl.attributeValue("parent") != null)
parentSection = sectionTable.get(Long.valueOf(sectionEl.attributeValue("parent")));
Placement placement = null;
if (timetable != null) {
placement = timetable.get(Long.parseLong(sectionEl.attributeValue("id")));
} else {
TimeLocation time = null;
Element timeEl = sectionEl.element("time");
if (timeEl != null) {
time = new TimeLocation(Integer.parseInt(timeEl.attributeValue("days"), 2), Integer.parseInt(timeEl.attributeValue("start")), Integer.parseInt(timeEl.attributeValue("length")), 0, 0, timeEl.attributeValue("datePattern") == null ? null : Long.valueOf(timeEl.attributeValue("datePattern")), timeEl.attributeValue("datePatternName", ""), createBitSet(timeEl.attributeValue("dates")), Integer.parseInt(timeEl.attributeValue("breakTime", "0")));
if (timeEl.attributeValue("pattern") != null)
time.setTimePatternId(Long.valueOf(timeEl.attributeValue("pattern")));
}
List<RoomLocation> rooms = new ArrayList<RoomLocation>();
for (Iterator<?> m = sectionEl.elementIterator("room"); m.hasNext(); ) {
Element roomEl = (Element) m.next();
Double posX = null, posY = null;
if (roomEl.attributeValue("location") != null) {
String loc = roomEl.attributeValue("location");
posX = Double.valueOf(loc.substring(0, loc.indexOf(',')));
posY = Double.valueOf(loc.substring(loc.indexOf(',') + 1));
}
RoomLocation room = new RoomLocation(Long.valueOf(roomEl.attributeValue("id")), roomEl.attributeValue("name", "R" + roomEl.attributeValue("id")), roomEl.attributeValue("building") == null ? null : Long.valueOf(roomEl.attributeValue("building")), 0, Integer.parseInt(roomEl.attributeValue("capacity")), posX, posY, "true".equals(roomEl.attributeValue("ignoreTooFar")), null);
rooms.add(room);
}
placement = (time == null ? null : new Placement(null, time, rooms));
}
List<Instructor> instructors = new ArrayList<Instructor>();
for (Iterator<?> m = sectionEl.elementIterator("instructor"); m.hasNext(); ) {
Element instructorEl = (Element) m.next();
instructors.add(new Instructor(Long.parseLong(instructorEl.attributeValue("id")), instructorEl.attributeValue("externalId"), instructorEl.attributeValue("name"), instructorEl.attributeValue("email")));
}
if (instructors.isEmpty() && sectionEl.attributeValue("instructorIds") != null)
instructors = Instructor.toInstructors(sectionEl.attributeValue("instructorIds"), sectionEl.attributeValue("instructorNames"));
Section section = new Section(Long.parseLong(sectionEl.attributeValue("id")), Integer.parseInt(sectionEl.attributeValue("limit")), sectionEl.attributeValue("name", "S" + sectionEl.attributeValue("id")), subpart, placement, instructors, parentSection);
section.setSpaceHeld(Double.parseDouble(sectionEl.attributeValue("hold", "0.0")));
section.setSpaceExpected(Double.parseDouble(sectionEl.attributeValue("expect", "0.0")));
section.setCancelled("true".equalsIgnoreCase(sectionEl.attributeValue("cancelled", "false")));
for (Iterator<?> m = sectionEl.elementIterator("cname"); m.hasNext(); ) {
Element cNameEl = (Element) m.next();
section.setName(Long.parseLong(cNameEl.attributeValue("id")), cNameEl.getText());
}
Element ignoreEl = sectionEl.element("no-conflicts");
if (ignoreEl != null) {
for (Iterator<?> m = ignoreEl.elementIterator("section"); m.hasNext(); ) section.addIgnoreConflictWith(Long.parseLong(((Element) m.next()).attributeValue("id")));
}
return section;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadStudent.
/**
* Load student
* @param studentEl student element
* @param offeringTable offering table
* @return loaded student
*/
protected Student loadStudent(Element studentEl, Map<Long, Offering> offeringTable) {
Student student = new Student(Long.parseLong(studentEl.attributeValue("id")), "true".equals(studentEl.attributeValue("dummy")));
student.setExternalId(studentEl.attributeValue("externalId"));
student.setName(studentEl.attributeValue("name"));
student.setStatus(studentEl.attributeValue("status"));
for (Iterator<?> j = studentEl.elementIterator(); j.hasNext(); ) {
Element requestEl = (Element) j.next();
if ("classification".equals(requestEl.getName())) {
student.getAcademicAreaClasiffications().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("major".equals(requestEl.getName())) {
student.getMajors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("minor".equals(requestEl.getName())) {
student.getMinors().add(new AcademicAreaCode(requestEl.attributeValue("area"), requestEl.attributeValue("code")));
} else if ("unavailability".equals(requestEl.getName())) {
Offering offering = offeringTable.get(Long.parseLong(requestEl.attributeValue("offering")));
Section section = (offering == null ? null : offering.getSection(Long.parseLong(requestEl.attributeValue("section"))));
if (section != null)
new Unavailability(student, section, "true".equals(requestEl.attributeValue("allowOverlap")));
} else if ("acm".equals(requestEl.getName())) {
student.getAreaClassificationMajors().add(new AreaClassificationMajor(requestEl.attributeValue("area"), requestEl.attributeValue("classification"), requestEl.attributeValue("major")));
}
}
return student;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadEnrollment.
/**
* Load enrollment
* @param enrollmentEl enrollment element (current, best, or initial)
* @param request parent request
* @return loaded enrollment
*/
protected Enrollment loadEnrollment(Element enrollmentEl, Request request) {
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
HashSet<Section> sections = new HashSet<Section>();
for (Iterator<?> k = enrollmentEl.elementIterator("section"); k.hasNext(); ) {
Element sectionEl = (Element) k.next();
Section section = courseRequest.getSection(Long.parseLong(sectionEl.attributeValue("id")));
sections.add(section);
}
Reservation reservation = null;
if (enrollmentEl.attributeValue("reservation", null) != null) {
long reservationId = Long.valueOf(enrollmentEl.attributeValue("reservation"));
for (Course course : courseRequest.getCourses()) for (Reservation r : course.getOffering().getReservations()) if (r.getId() == reservationId) {
reservation = r;
break;
}
}
if (!sections.isEmpty())
return courseRequest.createEnrollment(sections, reservation);
} else if (request instanceof FreeTimeRequest) {
return ((FreeTimeRequest) request).createEnrollment();
}
return null;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class LinkedSections method createConstraint.
/**
* Create linked-section constraints for a given student
*/
private LinkedSectionsConstraint createConstraint(Student student) {
List<Request> requests = new ArrayList<Request>();
int nrOfferings = 0;
requests: for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
for (Course course : ((CourseRequest) request).getCourses()) {
Map<Subpart, Set<Section>> subpartsThisOffering = iSections.get(course.getOffering());
if (subpartsThisOffering != null) {
requests.add(request);
nrOfferings++;
continue requests;
}
}
}
}
if (nrOfferings <= 1)
return null;
LinkedSectionsConstraint constraint = new LinkedSectionsConstraint(student, requests);
student.getRequests().get(0).getModel().addConstraint(constraint);
return constraint;
}
use of org.cpsolver.studentsct.model.Section 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();
}
}
Aggregations