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

aima.core.probability.domain.BooleanDomain 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.probability.domain;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Artificial Intelligence A Modern Approach (3rd Edition): page 486.
 * 
 * A Boolean random variable has the domain {true,false}.
 * 
 * @author Ciaran O'Reilly.
 */
public class BooleanDomain extends AbstractFiniteDomain {

	private static Set _possibleValues = null;
	static {
		// Keep consistent order
		_possibleValues = new LinkedHashSet();
		_possibleValues.add(Boolean.TRUE);
		_possibleValues.add(Boolean.FALSE);
		// Ensure cannot be modified
		_possibleValues = Collections.unmodifiableSet(_possibleValues);
	}

	public BooleanDomain() {
		indexPossibleValues(_possibleValues);
	}

	//
	// START-Domain
	@Override
	public int size() {
		return 2;
	}

	@Override
	public boolean isOrdered() {
		return false;
	}

	// END-Domain
	//

	//
	// START-DiscreteDomain
	@Override
	public Set getPossibleValues() {
		return _possibleValues;
	}

	// END-DiscreteDomain
	//

	@Override
	public boolean equals(Object o) {
		return o instanceof BooleanDomain;
	}

	@Override
	public int hashCode() {
		return _possibleValues.hashCode();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy