use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class SuggestionsBranchAndBound method computeSuggestions.
/**
* Perform the search
* @return an ordered set of possible suggestions
*/
public TreeSet<Suggestion> computeSuggestions() {
iT0 = System.currentTimeMillis();
iTimeoutReached = false;
iNrSolutionsSeen = 0;
iSuggestions.clear();
ArrayList<Request> requests2resolve = new ArrayList<Request>();
requests2resolve.add(iSelectedRequest);
TreeSet<Request> altRequests2resolve = new TreeSet<Request>();
for (Map.Entry<CourseRequest, Set<Section>> entry : iPreferredSections.entrySet()) {
CourseRequest request = entry.getKey();
Set<Section> sections = entry.getValue();
if (!sections.isEmpty() && sections.size() == sections.iterator().next().getSubpart().getConfig().getSubparts().size())
iAssignment.assign(0, request.createEnrollment(iAssignment, sections));
else if (!request.equals(iSelectedRequest)) {
if (sections.isEmpty())
altRequests2resolve.add(request);
else
requests2resolve.add(request);
}
}
for (Request request : iStudent.getRequests()) {
if (iAssignment.getValue(request) == null && request instanceof FreeTimeRequest) {
FreeTimeRequest ft = (FreeTimeRequest) request;
Enrollment enrollment = ft.createEnrollment();
if (iModel.conflictValues(iAssignment, enrollment).isEmpty())
iAssignment.assign(0, enrollment);
}
}
for (Request request : iStudent.getRequests()) {
request.setInitialAssignment(iAssignment.getValue(request));
}
backtrack(requests2resolve, altRequests2resolve, 0, iMaxDepth, false);
iT1 = System.currentTimeMillis();
return iSuggestions;
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class SectionConflictTable method createTable.
/**
* Create report
*
* @param assignment current assignment
* @param includeLastLikeStudents
* true, if last-like students should be included (i.e.,
* {@link Student#isDummy()} is true)
* @param includeRealStudents
* true, if real students should be included (i.e.,
* {@link Student#isDummy()} is false)
* @param useAmPm use 12-hour format
* @return report as comma separated text file
*/
public CSVFile createTable(Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
HashMap<Course, Map<Section, Double[]>> unavailabilities = new HashMap<Course, Map<Section, Double[]>>();
HashMap<Course, Set<Long>> totals = new HashMap<Course, Set<Long>>();
HashMap<CourseSection, Map<CourseSection, Double>> conflictingPairs = new HashMap<CourseSection, Map<CourseSection, Double>>();
HashMap<CourseSection, Double> sectionOverlaps = new HashMap<CourseSection, Double>();
for (Request request : new ArrayList<Request>(getModel().unassignedVariables(assignment))) {
if (request.getStudent().isDummy() && !includeLastLikeStudents)
continue;
if (!request.getStudent().isDummy() && !includeRealStudents)
continue;
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
if (courseRequest.getStudent().isComplete(assignment))
continue;
List<Enrollment> values = courseRequest.values(assignment);
SectionLimit limitConstraint = null;
for (GlobalConstraint<Request, Enrollment> c : getModel().globalConstraints()) {
if (c instanceof SectionLimit) {
limitConstraint = (SectionLimit) c;
break;
}
}
if (limitConstraint == null) {
limitConstraint = new SectionLimit(new DataProperties());
limitConstraint.setModel(getModel());
}
List<Enrollment> notAvailableValues = new ArrayList<Enrollment>(values.size());
List<Enrollment> availableValues = new ArrayList<Enrollment>(values.size());
for (Enrollment enrollment : values) {
if (limitConstraint.inConflict(assignment, enrollment))
notAvailableValues.add(enrollment);
else
availableValues.add(enrollment);
}
if (!notAvailableValues.isEmpty() && iType.hasUnavailabilities()) {
List<Enrollment> notOverlappingEnrollments = new ArrayList<Enrollment>(values.size());
enrollments: for (Enrollment enrollment : notAvailableValues) {
for (Request other : request.getStudent().getRequests()) {
if (other.equals(request) || assignment.getValue(other) == null || other instanceof FreeTimeRequest)
continue;
if (assignment.getValue(other).isOverlapping(enrollment))
continue enrollments;
}
// not overlapping
notOverlappingEnrollments.add(enrollment);
}
if (notOverlappingEnrollments.isEmpty() && availableValues.isEmpty() && iOverlapsAllEnrollments) {
double fraction = request.getWeight() / notAvailableValues.size();
Set<CourseSection> ones = new HashSet<CourseSection>();
for (Enrollment enrollment : notAvailableValues) {
boolean hasConflict = false;
for (Section s : enrollment.getSections()) {
if (s.getLimit() >= 0 && s.getEnrollmentWeight(assignment, request) + request.getWeight() > s.getLimit()) {
hasConflict = true;
break;
}
}
Map<Section, Double[]> sections = unavailabilities.get(enrollment.getCourse());
if (sections == null) {
sections = new HashMap<Section, Double[]>();
unavailabilities.put(enrollment.getCourse(), sections);
}
for (Section s : enrollment.getSections()) {
if (hasConflict && s.getLimit() < 0 || s.getEnrollmentWeight(assignment, request) + request.getWeight() <= s.getLimit())
continue;
Double[] total = sections.get(s);
sections.put(s, new Double[] { fraction + (total == null ? 0.0 : total[0].doubleValue()), (total == null ? 0.0 : total[1].doubleValue()) });
ones.add(new CourseSection(enrollment.getCourse(), s));
}
Set<Long> total = totals.get(enrollment.getCourse());
if (total == null) {
total = new HashSet<Long>();
totals.put(enrollment.getCourse(), total);
}
total.add(enrollment.getStudent().getId());
}
} else if (!notOverlappingEnrollments.isEmpty()) {
double fraction = request.getWeight() / notOverlappingEnrollments.size();
Set<CourseSection> ones = new HashSet<CourseSection>();
for (Enrollment enrollment : notOverlappingEnrollments) {
boolean hasConflict = false;
for (Section s : enrollment.getSections()) {
if (s.getLimit() >= 0 && s.getEnrollmentWeight(assignment, request) + request.getWeight() > s.getLimit()) {
hasConflict = true;
break;
}
}
Map<Section, Double[]> sections = unavailabilities.get(enrollment.getCourse());
if (sections == null) {
sections = new HashMap<Section, Double[]>();
unavailabilities.put(enrollment.getCourse(), sections);
}
for (Section s : enrollment.getSections()) {
if (hasConflict && s.getLimit() < 0 || s.getEnrollmentWeight(assignment, request) + request.getWeight() <= s.getLimit())
continue;
Double[] total = sections.get(s);
sections.put(s, new Double[] { fraction + (total == null ? 0.0 : total[0].doubleValue()), (total == null ? 0.0 : total[1].doubleValue()) });
ones.add(new CourseSection(enrollment.getCourse(), s));
}
Set<Long> total = totals.get(enrollment.getCourse());
if (total == null) {
total = new HashSet<Long>();
totals.put(enrollment.getCourse(), total);
}
total.add(enrollment.getStudent().getId());
}
for (CourseSection section : ones) {
Map<Section, Double[]> sections = unavailabilities.get(section.getCourse());
Double[] total = sections.get(section.getSection());
sections.put(section.getSection(), new Double[] { (total == null ? 0.0 : total[0].doubleValue()), request.getWeight() + (total == null ? 0.0 : total[1].doubleValue()) });
}
}
}
if (iOverlapsAllEnrollments)
availableValues = values;
if (!availableValues.isEmpty() && iType.hasOverlaps()) {
List<Map<CourseSection, List<CourseSection>>> conflicts = new ArrayList<Map<CourseSection, List<CourseSection>>>();
for (Enrollment enrollment : availableValues) {
Map<CourseSection, List<CourseSection>> overlaps = new HashMap<CourseSection, List<CourseSection>>();
for (Request other : request.getStudent().getRequests()) {
Enrollment otherEnrollment = assignment.getValue(other);
if (other.equals(request) || otherEnrollment == null || other instanceof FreeTimeRequest)
continue;
if (enrollment.isOverlapping(otherEnrollment))
for (Section a : enrollment.getSections()) for (Section b : otherEnrollment.getSections()) if (a.getTime() != null && b.getTime() != null && !a.isAllowOverlap() && !b.isAllowOverlap() && !a.isToIgnoreStudentConflictsWith(b.getId()) && a.getTime().hasIntersection(b.getTime()) && !canIgnore(assignment, enrollment, a, availableValues)) {
List<CourseSection> x = overlaps.get(new CourseSection(enrollment.getCourse(), a));
if (x == null) {
x = new ArrayList<CourseSection>();
overlaps.put(new CourseSection(enrollment.getCourse(), a), x);
}
x.add(new CourseSection(otherEnrollment.getCourse(), b));
}
}
if (!overlaps.isEmpty()) {
conflicts.add(overlaps);
Set<Long> total = totals.get(enrollment.getCourse());
if (total == null) {
total = new HashSet<Long>();
totals.put(enrollment.getCourse(), total);
}
total.add(enrollment.getStudent().getId());
}
}
double fraction = request.getWeight() / conflicts.size();
for (Map<CourseSection, List<CourseSection>> overlaps : conflicts) {
for (Map.Entry<CourseSection, List<CourseSection>> entry : overlaps.entrySet()) {
CourseSection a = entry.getKey();
Double total = sectionOverlaps.get(a);
sectionOverlaps.put(a, fraction + (total == null ? 0.0 : total.doubleValue()));
Map<CourseSection, Double> pair = conflictingPairs.get(a);
if (pair == null) {
pair = new HashMap<CourseSection, Double>();
conflictingPairs.put(a, pair);
}
for (CourseSection b : entry.getValue()) {
Double prev = pair.get(b);
pair.put(b, fraction + (prev == null ? 0.0 : prev.doubleValue()));
}
}
}
}
}
}
Comparator<Course> courseComparator = new Comparator<Course>() {
@Override
public int compare(Course a, Course b) {
int cmp = a.getName().compareTo(b.getName());
if (cmp != 0)
return cmp;
return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
}
};
Comparator<Section> sectionComparator = new Comparator<Section>() {
@Override
public int compare(Section a, Section b) {
int cmp = a.getSubpart().getConfig().getOffering().getName().compareTo(b.getSubpart().getConfig().getOffering().getName());
if (cmp != 0)
return cmp;
cmp = a.getSubpart().getInstructionalType().compareTo(b.getSubpart().getInstructionalType());
// cmp = a.getName().compareTo(b.getName());
if (cmp != 0)
return cmp;
return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
}
};
CSVFile csv = new CSVFile();
List<CSVFile.CSVField> headers = new ArrayList<CSVFile.CSVField>();
headers.add(new CSVFile.CSVField("Course"));
headers.add(new CSVFile.CSVField("Total\nConflicts"));
if (iType.hasUnavailabilities()) {
headers.add(new CSVFile.CSVField("Course\nEnrollment"));
headers.add(new CSVFile.CSVField("Course\nLimit"));
}
headers.add(new CSVFile.CSVField("Class"));
headers.add(new CSVFile.CSVField("Meeting Time"));
if (iType.hasUnavailabilities()) {
headers.add(new CSVFile.CSVField("Availability\nConflicts"));
headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
}
if (iType.hasOverlaps()) {
headers.add(new CSVFile.CSVField("Time\nConflicts"));
headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
}
if (iType.hasUnavailabilities()) {
headers.add(new CSVFile.CSVField("Class\nEnrollment"));
headers.add(new CSVFile.CSVField("Class\nLimit"));
if (!iType.hasOverlaps())
headers.add(new CSVFile.CSVField("Class\nPotential"));
}
if (iType.hasOverlaps()) {
headers.add(new CSVFile.CSVField("Conflicting\nClass"));
headers.add(new CSVFile.CSVField("Conflicting\nMeeting Time"));
headers.add(new CSVFile.CSVField("Joined\nConflicts"));
headers.add(new CSVFile.CSVField("% of Total\nConflicts"));
}
csv.setHeader(headers);
TreeSet<Course> courses = new TreeSet<Course>(courseComparator);
courses.addAll(totals.keySet());
for (Course course : courses) {
Map<Section, Double[]> sectionUnavailability = unavailabilities.get(course);
Set<Long> total = totals.get(course);
TreeSet<Section> sections = new TreeSet<Section>(sectionComparator);
if (sectionUnavailability != null)
sections.addAll(sectionUnavailability.keySet());
for (Map.Entry<CourseSection, Double> entry : sectionOverlaps.entrySet()) if (course.equals(entry.getKey().getCourse()))
sections.add(entry.getKey().getSection());
boolean firstCourse = true;
for (Section section : sections) {
Double[] sectionUnavailable = (sectionUnavailability == null ? null : sectionUnavailability.get(section));
Double sectionOverlap = sectionOverlaps.get(new CourseSection(course, section));
Map<CourseSection, Double> pair = conflictingPairs.get(new CourseSection(course, section));
if (pair == null) {
List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
line.add(new CSVFile.CSVField(firstCourse ? course.getName() : ""));
line.add(new CSVFile.CSVField(firstCourse ? total.size() : ""));
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(firstCourse ? sDF1.format(course.getEnrollmentWeight(assignment, null)) : ""));
line.add(new CSVFile.CSVField(firstCourse ? course.getLimit() < 0 ? "" : String.valueOf(course.getLimit()) : ""));
}
line.add(new CSVFile.CSVField(section.getSubpart().getName() + " " + section.getName(course.getId())));
line.add(new CSVFile.CSVField(section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm)));
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0]) : ""));
line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0] / total.size()) : ""));
}
if (iType.hasOverlaps()) {
line.add(new CSVFile.CSVField(sectionOverlap != null ? sDF2.format(sectionOverlap) : ""));
line.add(new CSVFile.CSVField(sectionOverlap != null ? sDF2.format(sectionOverlap / total.size()) : ""));
}
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(sDF1.format(section.getEnrollmentWeight(assignment, null))));
line.add(new CSVFile.CSVField(section.getLimit() < 0 ? "" : String.valueOf(section.getLimit())));
if (!iType.hasOverlaps())
line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF1.format(sectionUnavailable[1]) : ""));
}
csv.addLine(line);
} else {
boolean firstClass = true;
for (CourseSection other : new TreeSet<CourseSection>(pair.keySet())) {
List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getName() : ""));
line.add(new CSVFile.CSVField(firstCourse && firstClass ? total.size() : ""));
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(firstCourse && firstClass ? sDF1.format(course.getEnrollmentWeight(assignment, null)) : ""));
line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getLimit() < 0 ? "" : String.valueOf(course.getLimit()) : ""));
}
line.add(new CSVFile.CSVField(firstClass ? section.getSubpart().getName() + " " + section.getName(course.getId()) : ""));
line.add(new CSVFile.CSVField(firstClass ? section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm) : ""));
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(firstClass && sectionUnavailable != null ? sDF2.format(sectionUnavailable[0]) : ""));
line.add(new CSVFile.CSVField(sectionUnavailable != null ? sDF2.format(sectionUnavailable[0] / total.size()) : ""));
}
line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(sectionOverlap) : ""));
line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(sectionOverlap / total.size()) : ""));
if (iType.hasUnavailabilities()) {
line.add(new CSVFile.CSVField(firstClass ? sDF1.format(section.getEnrollmentWeight(assignment, null)) : ""));
line.add(new CSVFile.CSVField(firstClass ? section.getLimit() < 0 ? "" : String.valueOf(section.getLimit()) : ""));
}
line.add(new CSVFile.CSVField(other.getCourse().getName() + " " + other.getSection().getSubpart().getName() + " " + other.getSection().getName(other.getCourse().getId())));
line.add(new CSVFile.CSVField(other.getSection().getTime().getDayHeader() + " " + other.getSection().getTime().getStartTimeHeader(useAmPm) + " - " + other.getSection().getTime().getEndTimeHeader(useAmPm)));
line.add(new CSVFile.CSVField(sDF2.format(pair.get(other))));
line.add(new CSVFile.CSVField(sDF2.format(pair.get(other) / total.size())));
csv.addLine(line);
firstClass = false;
}
}
firstCourse = false;
}
csv.addLine();
}
return csv;
}
use of org.cpsolver.studentsct.model.Section 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.Section in project cpsolver by UniTime.
the class PriorityStudentWeights method getSelection.
/**
* Return how much the given enrollment is different from the selection (if any)
* @param enrollment given enrollment
* @return 0.0 when all the sections are the same, 1.0 when all the section are different (including different times)
*/
public double getSelection(Enrollment enrollment) {
if (enrollment.getStudent().isDummy())
return 1.0;
if (enrollment.isCourseRequest()) {
CourseRequest cr = (CourseRequest) enrollment.getRequest();
if (!cr.getSelectedChoices().isEmpty()) {
double similarSections = 0.0;
for (Section section : enrollment.getSections()) {
double bestChoice = 0.0;
for (Choice ch : cr.getSelectedChoices()) {
if (bestChoice < 1.0 && ch.sameSection(section)) {
bestChoice = 1.0;
} else if (bestChoice < iSameChoiceWeight && ch.sameChoice(section)) {
bestChoice = iSameChoiceWeight;
} else if (bestChoice < iSameTimeWeight && ch.sameInstructionalType(section) && ch.sameTime(section)) {
bestChoice = iSameTimeWeight;
} else if (bestChoice < iSameConfigWeight && ch.sameConfiguration(section)) {
bestChoice = iSameConfigWeight;
}
}
similarSections += bestChoice;
}
return 1.0 - similarSections / enrollment.getAssignments().size();
} else {
return 1.0;
}
} else {
return 1.0;
}
}
use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.
the class PriorityStudentWeights method main.
/**
* Test case -- run to see the weights for a few courses
* @param args program arguments
*/
public static void main(String[] args) {
PriorityStudentWeights pw = new PriorityStudentWeights(new DataProperties());
DecimalFormat df = new DecimalFormat("0.0000");
Student s = new Student(0l);
new CourseRequest(1l, 0, false, s, ToolBox.toList(new Course(1, "A", "1", new Offering(0, "A")), new Course(1, "A", "2", new Offering(0, "A")), new Course(1, "A", "3", new Offering(0, "A"))), false, null);
new CourseRequest(2l, 1, false, s, ToolBox.toList(new Course(1, "B", "1", new Offering(0, "B")), new Course(1, "B", "2", new Offering(0, "B")), new Course(1, "B", "3", new Offering(0, "B"))), false, null);
new CourseRequest(3l, 2, false, s, ToolBox.toList(new Course(1, "C", "1", new Offering(0, "C")), new Course(1, "C", "2", new Offering(0, "C")), new Course(1, "C", "3", new Offering(0, "C"))), false, null);
new CourseRequest(4l, 3, false, s, ToolBox.toList(new Course(1, "D", "1", new Offering(0, "D")), new Course(1, "D", "2", new Offering(0, "D")), new Course(1, "D", "3", new Offering(0, "D"))), false, null);
new CourseRequest(5l, 4, false, s, ToolBox.toList(new Course(1, "E", "1", new Offering(0, "E")), new Course(1, "E", "2", new Offering(0, "E")), new Course(1, "E", "3", new Offering(0, "E"))), false, null);
new CourseRequest(6l, 5, true, s, ToolBox.toList(new Course(1, "F", "1", new Offering(0, "F")), new Course(1, "F", "2", new Offering(0, "F")), new Course(1, "F", "3", new Offering(0, "F"))), false, null);
new CourseRequest(7l, 6, true, s, ToolBox.toList(new Course(1, "G", "1", new Offering(0, "G")), new Course(1, "G", "2", new Offering(0, "G")), new Course(1, "G", "3", new Offering(0, "G"))), false, null);
Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
Placement p = new Placement(null, new TimeLocation(1, 90, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("With one distance conflict:");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
w[i] = pw.getWeight(assignment, e, dc, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("With two distance conflicts:");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null)));
w[i] = pw.getWeight(assignment, e, dc, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("With 25% time overlapping conflict:");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<TimeOverlapsCounter.Conflict> toc = new HashSet<TimeOverlapsCounter.Conflict>();
toc.add(new TimeOverlapsCounter.Conflict(s, 3, e, sections.iterator().next(), e, sections.iterator().next()));
w[i] = pw.getWeight(assignment, e, null, toc);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("Disbalanced sections (by 2 / 10 students):");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
Subpart x = new Subpart(0, "Lec", "Lec", cfg, null);
Section a = new Section(0, 10, "x", x, p, null);
new Section(1, 10, "y", x, p, null);
sections.add(a);
a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("Same choice sections:");
pw.iMPP = true;
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<SctAssignment> other = new HashSet<SctAssignment>();
other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("Same time sections:");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<SctAssignment> other = new HashSet<SctAssignment>();
other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null, new Instructor(1l, null, "Josef Novak", null)));
cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("Different time sections:");
Placement q = new Placement(null, new TimeLocation(1, 102, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<SctAssignment> other = new HashSet<SctAssignment>();
other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), q, null));
cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
System.out.println("Two sections, one same choice, one same time:");
for (Request r : s.getRequests()) {
CourseRequest cr = (CourseRequest) r;
double[] w = new double[] { 0.0, 0.0, 0.0 };
for (int i = 0; i < cr.getCourses().size(); i++) {
Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
Set<SctAssignment> sections = new HashSet<SctAssignment>();
sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
sections.add(new Section(1, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null));
Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
Set<SctAssignment> other = new HashSet<SctAssignment>();
other.add(new Section(2, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
other.add(new Section(3, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null, new Instructor(1l, null, "Josef Novak", null)));
cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
w[i] = pw.getWeight(assignment, e, null, null);
}
System.out.println(cr + ": " + df.format(w[0]) + " " + df.format(w[1]) + " " + df.format(w[2]));
}
}
Aggregations