
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import smile.Network;
import smile.SMILEException;

public class Main {

	public static void main(String[] args) {
		try {
			Network net = new Network();
			net.readFile("Net_LearnedBySMILE_BN.xdsl");
			net.updateBeliefs();
			updateNet(net, "JDecInc2", "Wrong", new String[] { "AddExpression", "PreDecrementExpression", "PreIncrementExpression" });
		} catch (SMILEException e) {
			e.printStackTrace();
		}
	}

	public static void updateNet(Network net, String itemId, String itemValue, String[] requiredKCIds) {

		Set<String> bnNodes = new HashSet<String>(Arrays.asList(net.getAllNodeIds()));
		if (!bnNodes.contains(itemId)) {
			System.err.println("\tERROR: " + itemId + " is not in bn, no KC will be updated by BN!");
		}

		net.setEvidence(itemId, itemValue);
		net.updateBeliefs();
		net.clearEvidence(itemId);
		/*
		 * if the following line is commented, when we want to get network estimates for item nodes, the 
		 * network would throw exception, to avoid exception, we need to uncomment it 
		 */
		//net.updateBeliefs(); 
								
		System.out.println("****** Updated BN node values ******");
		bnNodes = new HashSet<String>(Arrays.asList(net.getAllNodeIds()));
		for (String bnId : bnNodes) {
			System.out.println(bnId + ": " + net.getNodeValue(bnId)[0]);
		}
	}
}
