protected void afterFactorAdd(Factor factor) { super.afterFactorAdd(factor); CPT cpt = (CPT) factor; Variable child = cpt.getChild(); VarSet parents = cpt.getParents(); allCpts.put(child, cpt); graph.addVertex(child); graph.addAllVertices(parents); for (Iterator it = parents.iterator(); it.hasNext(); ) { Variable rent = (Variable) it.next(); graph.addEdge(rent, child); } }
protected void beforeFactorAdd(Factor factor) { super.beforeFactorAdd(factor); if (!(factor instanceof CPT)) { throw new IllegalArgumentException( "Factors of a directed model must be an instance of CPT, was " + factor); } CPT cpt = (CPT) factor; Variable child = cpt.getChild(); VarSet parents = cpt.getParents(); if (graph.containsVertex(child)) { checkForNoCycle(parents, child, cpt); } }