All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.search.csp.NotEqualConstraint Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
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));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy