Search in sources :

Example 1 with InstructorConstraintContext

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;
}
Also used : InstructorConstraintContext(org.cpsolver.coursett.constraint.InstructorConstraint.InstructorConstraintContext) BitSet(java.util.BitSet) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint) InstructorConstraint(org.cpsolver.coursett.constraint.InstructorConstraint)

Aggregations

BitSet (java.util.BitSet)1 InstructorConstraint (org.cpsolver.coursett.constraint.InstructorConstraint)1 InstructorConstraintContext (org.cpsolver.coursett.constraint.InstructorConstraint.InstructorConstraintContext)1