use of org.cpsolver.studentsct.model.RequestGroup in project cpsolver by UniTime.
the class PriorityStudentWeights method getWeight.
@Override
public double getWeight(Assignment<Request, Enrollment> assignment, Enrollment enrollment) {
double weight = getCachedWeight(enrollment.getRequest());
switch(enrollment.getPriority()) {
case 1:
weight *= iFirstAlternativeFactor;
break;
case 2:
weight *= iSecondAlternativeFactor;
break;
}
if (enrollment.isCourseRequest() && iBalancingFactor != 0.0) {
double configUsed = enrollment.getConfig().getEnrollmentTotalWeight(assignment, enrollment.getRequest()) + enrollment.getRequest().getWeight();
double disbalanced = 0;
double total = 0;
for (Section section : enrollment.getSections()) {
Subpart subpart = section.getSubpart();
if (subpart.getSections().size() <= 1)
continue;
double used = section.getEnrollmentTotalWeight(assignment, enrollment.getRequest()) + enrollment.getRequest().getWeight();
// sections have limits -> desired size is section limit x (total enrollment / total limit)
// unlimited sections -> desired size is total enrollment / number of sections
double desired = (subpart.getLimit() > 0 ? section.getLimit() * (configUsed / subpart.getLimit()) : configUsed / subpart.getSections().size());
if (used > desired)
disbalanced += Math.min(enrollment.getRequest().getWeight(), used - desired) / enrollment.getRequest().getWeight();
else
disbalanced -= Math.min(enrollment.getRequest().getWeight(), desired - used) / enrollment.getRequest().getWeight();
total++;
}
if (disbalanced > 0)
weight *= (1.0 - disbalanced / total * iBalancingFactor);
}
if (iMPP) {
double difference = getDifference(enrollment);
if (difference > 0.0)
weight *= (1.0 - difference * iPerturbationFactor);
}
if (iSelectionFactor != 0.0) {
double selection = getSelection(enrollment);
if (selection > 0.0)
weight *= (1.0 - selection * iSelectionFactor);
}
if (enrollment.isCourseRequest() && iGroupFactor != 0.0) {
double sameGroup = 0.0;
int groupCount = 0;
for (RequestGroup g : ((CourseRequest) enrollment.getRequest()).getRequestGroups()) {
if (g.getCourse().equals(enrollment.getCourse())) {
sameGroup += g.getEnrollmentSpread(assignment, enrollment, iGroupBestRatio, iGroupFillRatio);
groupCount++;
}
}
if (groupCount > 0) {
double difference = 1.0 - sameGroup / groupCount;
weight *= (1.0 - difference * iGroupFactor);
}
}
return round(weight);
}
use of org.cpsolver.studentsct.model.RequestGroup in project cpsolver by UniTime.
the class StudentSectioningXMLLoader method loadCourseRequest.
/**
* Load course request
* @param requestEl request element
* @param student parent student
* @param offeringTable offering table
* @param courseTable course table
* @return loaded course request
*/
public CourseRequest loadCourseRequest(Element requestEl, Student student, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable) {
List<Course> courses = new ArrayList<Course>();
courses.add(courseTable.get(Long.valueOf(requestEl.attributeValue("course"))));
for (Iterator<?> k = requestEl.elementIterator("alternative"); k.hasNext(); ) courses.add(courseTable.get(Long.valueOf(((Element) k.next()).attributeValue("course"))));
Long timeStamp = null;
if (requestEl.attributeValue("timeStamp") != null)
timeStamp = Long.valueOf(requestEl.attributeValue("timeStamp"));
CourseRequest courseRequest = new CourseRequest(Long.parseLong(requestEl.attributeValue("id")), Integer.parseInt(requestEl.attributeValue("priority")), "true".equals(requestEl.attributeValue("alternative")), student, courses, "true".equals(requestEl.attributeValue("waitlist", "false")), timeStamp);
if (requestEl.attributeValue("weight") != null)
courseRequest.setWeight(Double.parseDouble(requestEl.attributeValue("weight")));
for (Iterator<?> k = requestEl.elementIterator("waitlisted"); k.hasNext(); ) {
Element choiceEl = (Element) k.next();
courseRequest.getWaitlistedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
}
for (Iterator<?> k = requestEl.elementIterator("selected"); k.hasNext(); ) {
Element choiceEl = (Element) k.next();
courseRequest.getSelectedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
}
groups: for (Iterator<?> k = requestEl.elementIterator("group"); k.hasNext(); ) {
Element groupEl = (Element) k.next();
long gid = Long.parseLong(groupEl.attributeValue("id"));
String gname = groupEl.attributeValue("name", "g" + gid);
Course course = courseTable.get(Long.valueOf(groupEl.attributeValue("course")));
for (RequestGroup g : course.getRequestGroups()) {
if (g.getId() == gid) {
courseRequest.addRequestGroup(g);
continue groups;
}
}
courseRequest.addRequestGroup(new RequestGroup(gid, gname, course));
}
return courseRequest;
}
Aggregations