Search in sources :

Example 1 with Context

use of org.cpsolver.instructor.model.Instructor.Context in project cpsolver by UniTime.

the class InstructorConstraint method computeConflicts.

@Override
public void computeConflicts(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) {
    Context context = value.getInstructor().getContext(assignment);
    // Check availability
    if (context.getInstructor().getTimePreference(value.variable().getRequest()).isProhibited()) {
        conflicts.add(value);
        return;
    }
    // Check for overlaps
    for (TeachingAssignment ta : context.getAssignments()) {
        if (ta.variable().equals(value.variable()) || conflicts.contains(ta))
            continue;
        if (ta.variable().getRequest().overlaps(value.variable().getRequest()))
            conflicts.add(ta);
    }
    // Same course and/or common
    for (TeachingAssignment ta : context.getAssignments()) {
        if (ta.variable().equals(value.variable()) || conflicts.contains(ta))
            continue;
        if (ta.variable().getRequest().isSameCourseViolated(value.variable().getRequest()) || ta.variable().getRequest().isSameCommonViolated(value.variable().getRequest()))
            conflicts.add(ta);
    }
    // Check load
    float load = value.variable().getRequest().getLoad();
    List<TeachingAssignment> adepts = new ArrayList<TeachingAssignment>();
    for (TeachingAssignment ta : context.getAssignments()) {
        if (ta.variable().equals(value.variable()) || conflicts.contains(ta))
            continue;
        adepts.add(ta);
        load += ta.variable().getRequest().getLoad();
    }
    while (load > context.getInstructor().getMaxLoad()) {
        if (adepts.isEmpty()) {
            conflicts.add(value);
            break;
        }
        TeachingAssignment conflict = ToolBox.random(adepts);
        load -= conflict.variable().getRequest().getLoad();
        adepts.remove(conflict);
        conflicts.add(conflict);
    }
}
Also used : Context(org.cpsolver.instructor.model.Instructor.Context) TeachingAssignment(org.cpsolver.instructor.model.TeachingAssignment) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 Context (org.cpsolver.instructor.model.Instructor.Context)1 TeachingAssignment (org.cpsolver.instructor.model.TeachingAssignment)1