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

aima.core.probability.proposition.AssignmentProposition 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 AssignmentProposition extends AbstractTermProposition {
	private Object value = null;
	//
	private String toString = null;

	public AssignmentProposition(RandomVariable forVariable, Object value) {
		super(forVariable);
		setValue(value);
	}

	public Object getValue() {
		return value;
	}
	
	public void setValue(Object value) {
		if (null == value) {
			throw new IllegalArgumentException(
					"The value for the Random Variable must be specified.");
		}
		this.value = value;
	}

	@Override
	public boolean holds(Map possibleWorld) {
		return value.equals(possibleWorld.get(getTermVariable()));
	}

	@Override
	public String toString() {
		if (null == toString) {
			StringBuilder sb = new StringBuilder();
			sb.append(getTermVariable().getName());
			sb.append(" = ");
			sb.append(value);

			toString = sb.toString();
		}
		return toString;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy