use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentSchedulingAssistantWeights method best.
private double[] best(Assignment<Request, Enrollment> assignment, CourseRequest cr) {
double[] cached = iCache.get(cr);
if (cached != null)
return cached;
double bestTime = 0;
Double bestOverExpected = null;
Double bestAvgPenalty = null;
double bestSelected = 0.0;
for (Course course : cr.getCourses()) {
for (Config config : course.getOffering().getConfigs()) {
int size = config.getSubparts().size();
double sectionsWithTime = 0;
double overExpected = 0;
double penalty = 0;
double selectedSections = 0;
for (Subpart subpart : config.getSubparts()) {
boolean hasTime = false;
Double sectionPenalty = null;
Double sectionOverExpected = null;
boolean hasSelection = false;
for (Section section : subpart.getSections()) {
if (section.getLimit() == 0)
continue;
if (section.getTime() != null)
hasTime = true;
if (!cr.getSelectedChoices().isEmpty() && cr.isSelected(section))
hasSelection = true;
if (sectionPenalty == null || sectionPenalty > section.getPenalty())
sectionPenalty = section.getPenalty();
double oexp = getOverExpected(assignment, section, cr);
if (sectionOverExpected == null || sectionOverExpected > oexp)
sectionOverExpected = oexp;
}
if (hasTime)
sectionsWithTime++;
if (sectionPenalty != null)
penalty += sectionPenalty;
if (hasSelection)
selectedSections++;
if (sectionOverExpected != null)
overExpected += sectionOverExpected;
}
if (sectionsWithTime / size > bestTime)
bestTime = sectionsWithTime / size;
if (bestOverExpected == null || overExpected < bestOverExpected)
bestOverExpected = overExpected;
if (bestAvgPenalty == null || penalty / size < bestAvgPenalty)
bestAvgPenalty = penalty / size;
if (selectedSections / size > bestSelected)
bestSelected = selectedSections / size;
}
}
cached = new double[] { bestTime, (bestOverExpected == null ? 0.0 : bestOverExpected), (bestAvgPenalty == null ? 0.0 : bestAvgPenalty), bestSelected };
iCache.put(cr, cached);
return cached;
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class SuggestionsBranchAndBound method values.
/**
* Domain of a request
* @param request given request
* @return possible enrollments (meeting the filter etc)
*/
protected List<Enrollment> values(final Request request) {
if (!request.getStudent().canAssign(iAssignment, request))
return new ArrayList<Enrollment>();
List<Enrollment> values = iValues.get(request);
if (values != null)
return values;
if (request instanceof CourseRequest) {
CourseRequest cr = (CourseRequest) request;
values = (cr.equals(iSelectedRequest) ? cr.getAvaiableEnrollments(iAssignment) : cr.getAvaiableEnrollmentsSkipSameTime(iAssignment));
Collections.sort(values, new Comparator<Enrollment>() {
@Override
public int compare(Enrollment e1, Enrollment e2) {
return iComparator.compare(iAssignment, e1, e2);
}
});
} else {
values = new ArrayList<Enrollment>();
values.add(((FreeTimeRequest) request).createEnrollment());
}
if (canLeaveUnassigned(request)) {
Config config = null;
if (request instanceof CourseRequest)
config = ((CourseRequest) request).getCourses().get(0).getOffering().getConfigs().get(0);
values.add(new Enrollment(request, 0, config, new HashSet<Section>(), iAssignment));
}
iValues.put(request, values);
if (request.equals(iSelectedRequest) && iFilter != null && request instanceof CourseRequest) {
for (Iterator<Enrollment> i = values.iterator(); i.hasNext(); ) {
Enrollment enrollment = i.next();
if (enrollment.getAssignments() != null && !enrollment.getAssignments().isEmpty()) {
boolean match = false;
for (Iterator<Section> j = enrollment.getSections().iterator(); j.hasNext(); ) {
Section section = j.next();
if (iSelectedSection != null) {
if (section.getSubpart().getId() == iSelectedSection.getSubpart().getId()) {
if (iFilter.match(enrollment.getCourse(), section)) {
match = true;
break;
}
}
if (section.getSubpart().getConfig().getId() != iSelectedSection.getSubpart().getConfig().getId() && section.getSubpart().getInstructionalType().equals(iSelectedSection.getSubpart().getInstructionalType())) {
if (iFilter.match(enrollment.getCourse(), section)) {
match = true;
break;
}
}
} else {
if (iFilter.match(enrollment.getCourse(), section)) {
match = true;
break;
}
}
}
if (!match)
i.remove();
}
}
}
if (request.equals(iSelectedRequest))
iMatched = values.size();
return values;
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class StudentChoiceOrder method avgNrChoices.
/** Average number of choices for each student
* @param student given student
* @return average number of choices of the given student
**/
public double avgNrChoices(Student student) {
int nrRequests = 0;
int nrChoices = 0;
for (Request request : student.getRequests()) {
if (request instanceof CourseRequest) {
CourseRequest cr = (CourseRequest) request;
for (Course course : cr.getCourses()) {
for (Config config : course.getOffering().getConfigs()) {
Integer nrChoicesThisCfg = iCache.get(config);
if (nrChoicesThisCfg == null) {
nrChoicesThisCfg = new Integer(nrChoices(config, 0, new HashSet<Section>()));
iCache.put(config, nrChoicesThisCfg);
}
nrChoices += nrChoicesThisCfg.intValue();
}
}
nrRequests++;
}
}
return (nrRequests == 0 ? 0.0 : ((double) nrChoices) / nrRequests);
}
use of org.cpsolver.studentsct.model.Config in project cpsolver by UniTime.
the class Test method getPercDisbalancedSections.
public double getPercDisbalancedSections(Assignment<Request, Enrollment> assignment, double perc) {
boolean balanceUnlimited = model().getProperties().getPropertyBoolean("General.BalanceUnlimited", false);
double disb10Sections = 0, nrSections = 0;
for (Offering offering : model().getOfferings()) {
for (Config config : offering.getConfigs()) {
double enrl = config.getEnrollmentTotalWeight(assignment, null);
for (Subpart subpart : config.getSubparts()) {
if (subpart.getSections().size() <= 1)
continue;
nrSections += subpart.getSections().size();
if (subpart.getLimit() > 0) {
// sections have limits -> desired size is section limit
// x (total enrollment / total limit)
double ratio = enrl / subpart.getLimit();
for (Section section : subpart.getSections()) {
double desired = ratio * section.getLimit();
if (Math.abs(desired - section.getEnrollmentTotalWeight(assignment, null)) >= Math.max(1.0, perc * section.getLimit()))
disb10Sections++;
}
} else if (balanceUnlimited) {
// enrollment / number of sections
for (Section section : subpart.getSections()) {
double desired = enrl / subpart.getSections().size();
if (Math.abs(desired - section.getEnrollmentTotalWeight(assignment, null)) >= Math.max(1.0, perc * desired))
disb10Sections++;
}
}
}
}
}
return 100.0 * disb10Sections / nrSections;
}
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 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", "curriculum");
CurriculumReservation cr = (CurriculumReservation) reservation;
if (cr.getReservationLimit() >= 0.0)
reservationEl.addAttribute("limit", String.valueOf(cr.getReservationLimit()));
reservationEl.addAttribute("area", cr.getAcademicArea());
for (String clasf : cr.getClassifications()) reservationEl.addElement("classification").addAttribute("code", clasf);
for (String major : cr.getMajors()) reservationEl.addElement("major").addAttribute("code", major);
} 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");
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