Search in sources :

Example 11 with TeachingAssignment

use of org.cpsolver.instructor.model.TeachingAssignment in project cpsolver by UniTime.

the class SameLinkConstraint method getCurrentPreference.

/**
 * Current constraint preference (if soft)
 * @param assignment current assignment
 * @param value proposed change
 * @return change in the current preference value of this constraint
 */
public int getCurrentPreference(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value) {
    // no preference
    if (isHard())
        return 0;
    TeachingAssignment current = assignment.getValue(value.variable());
    if (current != null && current.getInstructor().equals(value.getInstructor()))
        return 0;
    int ret = 0;
    if (getPreference() < 0) {
        // preferred
        for (TeachingAssignment other : value.getInstructor().getContext(assignment).getAssignments()) {
            if (!variables().equals(value.variable()) && !variables().contains(other.variable())) {
                ret++;
            }
        }
        if (current != null) {
            for (TeachingAssignment other : current.getInstructor().getContext(assignment).getAssignments()) {
                if (!variables().equals(value.variable()) && !variables().contains(other.variable())) {
                    ret--;
                }
            }
        }
    } else if (getPreference() > 0) {
        for (TeachingAssignment other : value.getInstructor().getContext(assignment).getAssignments()) {
            if (!variables().equals(value.variable()) && variables().contains(other.variable()))
                ret++;
        }
        if (current != null) {
            for (TeachingAssignment other : current.getInstructor().getContext(assignment).getAssignments()) {
                if (!variables().equals(value.variable()) && variables().contains(other.variable())) {
                    ret--;
                }
            }
        }
    }
    return ret;
}
Also used : TeachingAssignment(org.cpsolver.instructor.model.TeachingAssignment)

Aggregations

TeachingAssignment (org.cpsolver.instructor.model.TeachingAssignment)11 Instructor (org.cpsolver.instructor.model.Instructor)7 TeachingRequest (org.cpsolver.instructor.model.TeachingRequest)7 File (java.io.File)4 PrintWriter (java.io.PrintWriter)4 DecimalFormat (java.text.DecimalFormat)3 HashSet (java.util.HashSet)3 Section (org.cpsolver.instructor.model.Section)3 Course (org.cpsolver.instructor.model.Course)2 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 TimeLocation (org.cpsolver.coursett.model.TimeLocation)1 Assignment (org.cpsolver.ifs.assignment.Assignment)1 DefaultParallelAssignment (org.cpsolver.ifs.assignment.DefaultParallelAssignment)1 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)1 AssignmentConstraintContext (org.cpsolver.ifs.assignment.context.AssignmentConstraintContext)1