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

aima.core.probability.proposition.ConjunctiveProposition Maven / Gradle / Ivy

Go to download

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

The newest version!
package aima.core.probability.proposition;

import java.util.Map;

import aima.core.probability.RandomVariable;

public class ConjunctiveProposition extends AbstractProposition implements
		BinarySentenceProposition {

	private Proposition left = null;
	private Proposition right = null;
	//
	private String toString = null;

	public ConjunctiveProposition(Proposition left, Proposition right) {
		if (null == left) {
			throw new IllegalArgumentException(
					"Left side of conjunction must be specified.");
		}
		if (null == right) {
			throw new IllegalArgumentException(
					"Right side of conjunction must be specified.");
		}
		// Track nested scope
		addScope(left.getScope());
		addScope(right.getScope());
		addUnboundScope(left.getUnboundScope());
		addUnboundScope(right.getUnboundScope());

		this.left = left;
		this.right = right;
	}

	@Override
	public boolean holds(Map possibleWorld) {
		return left.holds(possibleWorld) && right.holds(possibleWorld);
	}

	@Override
	public String toString() {
		if (null == toString) {
			StringBuilder sb = new StringBuilder();
			sb.append("(");
			sb.append(left.toString());
			sb.append(" AND ");
			sb.append(right.toString());
			sb.append(")");

			toString = sb.toString();
		}

		return toString;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy