use of org.cpsolver.coursett.constraint.InstructorConstraint.InstructorConstraintContext in project cpsolver by UniTime.
the class InstructorLunchBreak method getValue.
@Override
public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
double ret = 0.0;
if (value.getTimeLocation().getStartSlot() <= iLunchEnd && value.getTimeLocation().getStartSlot() + value.getTimeLocation().getLength() > iLunchStart) {
InstructorLunchBreakContext context = (InstructorLunchBreakContext) getContext(assignment);
for (InstructorConstraint constraint : value.variable().getInstructorConstraints()) {
InstructorConstraintContext icx = constraint.getContext(assignment);
CompactInfo compactInfo = context.getCompactInfo(constraint);
for (int i = 0; i < Constants.NR_DAYS; i++) {
// checks only days affected by the placement
if ((value.getTimeLocation().getDayCode() & Constants.DAY_CODES[i]) != 0) {
int currentLunchStartSlot = Constants.SLOTS_PER_DAY * i + iLunchStart;
int currentLunchEndSlot = Constants.SLOTS_PER_DAY * i + iLunchEnd;
int semesterViolations = 0;
for (BitSet week : getWeeks()) {
int maxBreak = 0;
int currentBreak = 0;
for (int slot = currentLunchStartSlot; slot < currentLunchEndSlot; slot++) {
if (isEmpty(icx, slot, week, value)) {
currentBreak++;
if (maxBreak < currentBreak) {
maxBreak = currentBreak;
}
} else {
currentBreak = 0;
}
}
if (maxBreak < iLunchLength) {
semesterViolations++;
}
}
// add the difference to the result
ret += semesterViolations - compactInfo.getLunchDayViolations()[i];
}
}
}
}
return ret;
}
Aggregations