use of org.cpsolver.studentsct.model.Enrollment in project cpsolver by UniTime.
the class DistanceConflict method countTotalNrConflicts.
/**
* Compute the actual number of all distance conflicts. Should be equal to
* {@link DistanceConflict#getTotalNrConflicts(Assignment)}.
* @param assignment current assignment
* @return computed number of all distance conflicts
*/
public int countTotalNrConflicts(Assignment<Request, Enrollment> assignment) {
int total = 0;
for (Request r1 : getModel().variables()) {
if (assignment.getValue(r1) == null || !(r1 instanceof CourseRequest))
continue;
Enrollment e1 = assignment.getValue(r1);
total += nrConflicts(e1);
for (Request r2 : r1.getStudent().getRequests()) {
Enrollment e2 = assignment.getValue(r2);
if (e2 == null || r1.getId() >= r2.getId() || !(r2 instanceof CourseRequest))
continue;
total += nrConflicts(e1, e2);
}
}
return total;
}
use of org.cpsolver.studentsct.model.Enrollment in project cpsolver by UniTime.
the class Test method getMinMaxEnrollmentPenalty.
/**
* Minimum and maximum enrollment penalty, i.e.,
* {@link Enrollment#getPenalty()} of all enrollments
* @param request a course request
* @return minimum and maximum of the enrollment penalty
*/
public static double[] getMinMaxEnrollmentPenalty(CourseRequest request) {
List<Enrollment> enrollments = request.values(new EmptyAssignment<Request, Enrollment>());
if (enrollments.isEmpty())
return new double[] { 0, 0 };
double min = Double.MAX_VALUE, max = Double.MIN_VALUE;
for (Enrollment enrollment : enrollments) {
double penalty = enrollment.getPenalty();
min = Math.min(min, penalty);
max = Math.max(max, penalty);
}
return new double[] { min, max };
}
use of org.cpsolver.studentsct.model.Enrollment in project cpsolver by UniTime.
the class Test method getMinMaxAvailableEnrollmentPenalty.
/**
* Minimum and maximum available enrollment penalty, i.e.,
* {@link Enrollment#getPenalty()} of all available enrollments
* @param assignment current assignment
* @param request a course request
* @return minimum and maximum of the available enrollment penalty
*/
public static double[] getMinMaxAvailableEnrollmentPenalty(Assignment<Request, Enrollment> assignment, CourseRequest request) {
List<Enrollment> enrollments = request.getAvaiableEnrollments(assignment);
if (enrollments.isEmpty())
return new double[] { 0, 0 };
double min = Double.MAX_VALUE, max = Double.MIN_VALUE;
for (Enrollment enrollment : enrollments) {
double penalty = enrollment.getPenalty();
min = Math.min(min, penalty);
max = Math.max(max, penalty);
}
return new double[] { min, max };
}
use of org.cpsolver.studentsct.model.Enrollment in project cpsolver by UniTime.
the class Test method batchSectioning.
/** Batch sectioning test
* @param cfg solver configuration
* @return resultant solution
**/
public static Solution<Request, Enrollment> batchSectioning(DataProperties cfg) {
Solution<Request, Enrollment> solution = load(cfg);
if (solution == null)
return null;
StudentSectioningModel model = (StudentSectioningModel) solution.getModel();
if (cfg.getPropertyBoolean("Test.ComputeSectioningInfo", true))
model.clearOnlineSectioningInfos();
Progress.getInstance(model).addProgressListener(new ProgressWriter(System.out));
solve(solution, cfg);
return solution;
}
use of org.cpsolver.studentsct.model.Enrollment in project cpsolver by UniTime.
the class LinkedSections method computeConflicts.
/**
* Compute conflicting enrollments. If the given enrollment contains sections of this link
* (one for each subpart in {@link LinkedSections#getSubparts(Offering)}), another assignment
* of this student is in a conflict, if it does not contain the appropriate sections from
* {@link LinkedSections#getSubparts(Offering)} and {@link LinkedSections#getSections(Subpart)}.
*
* @param enrollment given enrollment
* @param assignment custom assignment
* @param conflicts found conflicts are given to this interface, see {@link ConflictHandler#onConflict(Enrollment)}
*/
public void computeConflicts(Enrollment enrollment, EnrollmentAssignment assignment, ConflictHandler conflicts) {
if (enrollment == null || enrollment.getCourse() == null)
return;
Map<Subpart, Set<Section>> subparts = iSections.get(enrollment.getCourse().getOffering());
if (subparts == null || subparts.isEmpty())
return;
boolean match = false, partial = false;
for (Section section : enrollment.getSections()) {
Set<Section> sections = subparts.get(section.getSubpart());
if (sections != null) {
if (sections.contains(section))
match = true;
else
partial = true;
}
}
boolean full = match && !partial;
if (isMustBeUsed()) {
if (!full) {
// not full match -> conflict if there is no other linked section constraint with a full match
// check if there is some other constraint taking care of this case
boolean hasOtherMatch = false;
for (LinkedSections other : enrollment.getStudent().getLinkedSections()) {
if (other.hasFullMatch(enrollment) && nrSharedOfferings(other) > 1) {
hasOtherMatch = true;
break;
}
}
// no other match -> problem
if (!hasOtherMatch && !conflicts.onConflict(enrollment))
return;
}
}
if (full) {
// full match -> check other enrollments
for (int i = 0; i < enrollment.getStudent().getRequests().size(); i++) {
Request request = enrollment.getStudent().getRequests().get(i);
// given enrollment
if (request.equals(enrollment.getRequest()))
continue;
Enrollment otherEnrollment = assignment.getEnrollment(request, i);
// not assigned or not course request
if (otherEnrollment == null || otherEnrollment.getCourse() == null)
continue;
Map<Subpart, Set<Section>> otherSubparts = iSections.get(otherEnrollment.getCourse().getOffering());
// offering is not in the link
if (otherSubparts == null || otherSubparts.isEmpty())
continue;
boolean otherMatch = false, otherPartial = false;
for (Section section : otherEnrollment.getSections()) {
Set<Section> otherSections = otherSubparts.get(section.getSubpart());
if (otherSections != null) {
if (otherSections.contains(section))
otherMatch = true;
else
otherPartial = true;
}
}
boolean otherFull = otherMatch && !otherPartial;
// not full match -> conflict
if (!otherFull && !conflicts.onConflict(otherEnrollment))
return;
}
} else {
// no or only partial match -> there should be no match in other offerings too
for (int i = 0; i < enrollment.getStudent().getRequests().size(); i++) {
Request request = enrollment.getStudent().getRequests().get(i);
// given enrollment
if (request.equals(enrollment.getRequest()))
continue;
Enrollment otherEnrollment = assignment.getEnrollment(request, i);
// not assigned or not course request
if (otherEnrollment == null || otherEnrollment.getCourse() == null)
continue;
Map<Subpart, Set<Section>> otherSubparts = iSections.get(otherEnrollment.getCourse().getOffering());
// offering is not in the link
if (otherSubparts == null || otherSubparts.isEmpty())
continue;
boolean otherMatch = false, otherPartial = false;
for (Section section : otherEnrollment.getSections()) {
Set<Section> otherSections = otherSubparts.get(section.getSubpart());
if (otherSections != null) {
if (otherSections.contains(section))
otherMatch = true;
else
otherPartial = true;
}
}
boolean otherFull = otherMatch && !otherPartial;
// full match -> conflict
if (otherFull && !conflicts.onConflict(otherEnrollment))
return;
}
}
}
Aggregations