use of org.logicng.knowledgecompilation.bdds.datastructures.BDDNode in project LogicNG by logic-ng.
the class LngBDDFunction method apply.
@Override
public BDDNode apply(final BDD bdd) {
final BDDKernel kernel = bdd.underlyingKernel();
final int index = bdd.index();
final Map<Integer, int[]> kernelNodeMap = new BDDOperations(kernel).allNodes(index).stream().collect(Collectors.toMap(node -> node[0], node -> node));
return buildBDDNode(index, kernel, kernelNodeMap, new HashMap<>());
}
use of org.logicng.knowledgecompilation.bdds.datastructures.BDDNode in project LogicNG by logic-ng.
the class LngBDDFunction method buildBDDNode.
private BDDNode buildBDDNode(final int index, final BDDKernel kernel, final Map<Integer, int[]> kernelNodeMap, final Map<Integer, BDDNode> nodeMap) {
BDDNode node = nodeMap.get(index);
if (node != null) {
return node;
}
if (index == BDDKernel.BDD_FALSE) {
node = BDDConstant.getFalsumNode(kernel.factory());
} else if (index == BDDKernel.BDD_TRUE) {
node = BDDConstant.getVerumNode(kernel.factory());
} else {
final int[] kernelNode = kernelNodeMap.get(index);
final Variable variable = kernel.getVariableForIndex(kernelNode[1]);
final BDDNode lowNode = buildBDDNode(kernelNode[2], kernel, kernelNodeMap, nodeMap);
final BDDNode highNode = buildBDDNode(kernelNode[3], kernel, kernelNodeMap, nodeMap);
node = new BDDInnerNode(variable, lowNode, highNode);
}
nodeMap.put(index, node);
return node;
}
Aggregations