use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class BacktrackSelection method init.
public void init(Solver<Request, Enrollment> solver, String name) {
List<Request> variables = new ArrayList<Request>(iIncludeAssignedRequests ? solver.currentSolution().getModel().variables() : solver.currentSolution().getModel().unassignedVariables(solver.currentSolution().getAssignment()));
Collections.shuffle(variables);
iRequests = new LinkedList<Request>(variables);
if (iRBtNSel == null) {
try {
iRBtNSel = new RandomizedBacktrackNeighbourSelection(solver.getProperties());
iRBtNSel.init(solver);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Progress.getInstance(solver.currentSolution().getModel()).setPhase(name, variables.size());
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class Test method updateSpace.
public static void updateSpace(Assignment<Request, Enrollment> assignment, Enrollment enrollment, boolean increment) {
if (enrollment == null || !enrollment.isCourseRequest())
return;
for (Section section : enrollment.getSections()) section.setSpaceHeld(section.getSpaceHeld() + (increment ? 1.0 : -1.0));
List<Enrollment> feasibleEnrollments = new ArrayList<Enrollment>();
int totalLimit = 0;
for (Enrollment enrl : enrollment.getRequest().values(assignment)) {
if (!enrl.getCourse().equals(enrollment.getCourse()))
continue;
boolean overlaps = false;
for (Request otherRequest : enrollment.getRequest().getStudent().getRequests()) {
if (otherRequest.equals(enrollment.getRequest()) || !(otherRequest instanceof CourseRequest))
continue;
Enrollment otherErollment = assignment.getValue(otherRequest);
if (otherErollment == null)
continue;
if (enrl.isOverlapping(otherErollment)) {
overlaps = true;
break;
}
}
if (!overlaps) {
feasibleEnrollments.add(enrl);
if (totalLimit >= 0) {
int limit = enrl.getLimit();
if (limit < 0)
totalLimit = -1;
else
totalLimit += limit;
}
}
}
double change = enrollment.getRequest().getWeight() / (totalLimit > 0 ? totalLimit : feasibleEnrollments.size());
for (Enrollment feasibleEnrollment : feasibleEnrollments) for (Section section : feasibleEnrollment.getSections()) {
if (totalLimit > 0) {
section.setSpaceExpected(section.getSpaceExpected() + (increment ? +change : -change) * feasibleEnrollment.getLimit());
} else {
section.setSpaceExpected(section.getSpaceExpected() + (increment ? +change : -change));
}
}
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class EnrollmentSelection method isAllowed.
/** true, if it is allowed to assign given value
* @param assignment current assignment
* @param value given value
* @param conflicts conflicting assignments
* @return true if it is allowed
**/
public boolean isAllowed(Assignment<Request, Enrollment> assignment, Enrollment value, Set<Enrollment> conflicts) {
if (value == null)
return true;
StudentSectioningModel model = (StudentSectioningModel) value.variable().getModel();
if (model.getNrLastLikeRequests(false) == 0 || model.getNrRealRequests(false) == 0)
return true;
Request request = value.variable();
if (request.getStudent().isDummy()) {
if (conflicts == null)
conflicts = value.variable().getModel().conflictValues(assignment, value);
for (Enrollment conflict : conflicts) {
if (!conflict.getRequest().getStudent().isDummy())
return false;
}
} else {
if (conflicts == null)
conflicts = value.variable().getModel().conflictValues(assignment, value);
if (conflicts.size() > (assignment.getValue(request) == null ? 1 : 0))
return false;
}
return true;
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class OnlineSelection method updateSpace.
/** Update online sectioning info after the given student is sectioned
* @param assignment current assignment
* @param student student in question
**/
public void updateSpace(Assignment<Request, Enrollment> assignment, Student student) {
for (Request request : student.getRequests()) {
if (!(request instanceof CourseRequest))
continue;
CourseRequest courseRequest = (CourseRequest) request;
Enrollment enrollment = assignment.getValue(courseRequest);
if (enrollment == null)
// not enrolled --> no update
return;
for (Section section : enrollment.getSections()) {
section.setSpaceHeld(section.getSpaceHeld() - courseRequest.getWeight());
// sLog.debug(" -- space held for "+section+" decreased by 1 (to "+section.getSpaceHeld()+")");
}
List<Enrollment> feasibleEnrollments = new ArrayList<Enrollment>();
for (Enrollment enrl : courseRequest.values(assignment)) {
boolean overlaps = false;
for (Request otherRequest : courseRequest.getStudent().getRequests()) {
if (otherRequest.equals(courseRequest) || !(otherRequest instanceof CourseRequest))
continue;
Enrollment otherErollment = assignment.getValue(otherRequest);
if (otherErollment == null)
continue;
if (enrl.isOverlapping(otherErollment)) {
overlaps = true;
break;
}
}
if (!overlaps)
feasibleEnrollments.add(enrl);
}
double decrement = courseRequest.getWeight() / feasibleEnrollments.size();
for (Enrollment feasibleEnrollment : feasibleEnrollments) {
for (Section section : feasibleEnrollment.getSections()) {
section.setSpaceExpected(section.getSpaceExpected() - decrement);
// sLog.debug(" -- space expected for "+section+" decreased by "+decrement+" (to "+section.getSpaceExpected()+")");
}
}
}
}
use of org.cpsolver.studentsct.model.Request in project cpsolver by UniTime.
the class PriorityConstructionSelection method branchAndBound.
/**
* Find best solution for the next student using {@link BranchBoundSelection}.
* @param solution current selection
* @return generated neighbour
*/
public Neighbour<Request, Enrollment> branchAndBound(Solution<Request, Enrollment> solution) {
while (iStudentsEnumeration.hasNext()) {
Student student = iStudentsEnumeration.next();
Progress.getInstance(solution.getModel()).incProgress();
/*
if (student.nrRequests() < iCycle) {
// not enough requests -> nothing to improve -> skip
continue;
}
if (student.nrAssignedRequests() + 1 < iCycle) {
// previous step cycle already did not improve the assignment -> skip
continue;
}
*/
Neighbour<Request, Enrollment> neighbour = iBranchBoundSelection.getSelection(solution.getAssignment(), student).select();
if (neighbour != null)
return neighbour;
}
return null;
}
Aggregations