use of org.cpsolver.studentsct.model.Request 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.Request 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.Request 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;
}
}
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class AssignInitialSelection method selectNeighbour.
@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
Student student = null;
while ((student = nextStudent()) != null) {
Progress.getInstance(solution.getModel()).incProgress();
if (student.nrAssignedRequests(solution.getAssignment()) > 0)
continue;
Neighbour<Request, Enrollment> neighbour = new InitialSelection(student, solution.getAssignment()).select();
if (neighbour != null)
return neighbour;
}
return null;
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class BacktrackSelection method selectNeighbour.
@Override
public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
Request request = null;
while ((request = nextRequest()) != null) {
Progress.getInstance(solution.getModel()).incProgress();
Neighbour<Request, Enrollment> n = iRBtNSel.selectNeighbour(solution, request);
if (n != null && n.value(solution.getAssignment()) <= 0.0)
return n;
}
return null;
}
Aggregations