aima.core.search.csp.NotEqualConstraint Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
package aima.core.search.csp;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a binary constraint which forbids equal values.
*
* @author Ruediger Lunde
*/
public class NotEqualConstraint implements Constraint {
private Variable var1;
private Variable var2;
private List scope;
public NotEqualConstraint(Variable var1, Variable var2) {
this.var1 = var1;
this.var2 = var2;
scope = new ArrayList(2);
scope.add(var1);
scope.add(var2);
}
@Override
public List getScope() {
return scope;
}
@Override
public boolean isSatisfiedWith(Assignment assignment) {
Object value1 = assignment.getAssignment(var1);
return value1 == null || !value1.equals(assignment.getAssignment(var2));
}
}