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;
}
Aggregations