Search in sources :

Example 1 with BDDNode

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<>());
}
Also used : BDDNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDNode) BDD(org.logicng.knowledgecompilation.bdds.BDD) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) Variable(org.logicng.formulas.Variable) Map(java.util.Map) BDDInnerNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode) BDDConstant(org.logicng.knowledgecompilation.bdds.datastructures.BDDConstant) BDDOperations(org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) BDDKernel(org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel) BDDOperations(org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations)

Example 2 with BDDNode

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;
}
Also used : Variable(org.logicng.formulas.Variable) BDDInnerNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode) BDDNode(org.logicng.knowledgecompilation.bdds.datastructures.BDDNode)

Aggregations

Variable (org.logicng.formulas.Variable)2 BDDInnerNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDInnerNode)2 BDDNode (org.logicng.knowledgecompilation.bdds.datastructures.BDDNode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BDD (org.logicng.knowledgecompilation.bdds.BDD)1 BDDConstant (org.logicng.knowledgecompilation.bdds.datastructures.BDDConstant)1 BDDKernel (org.logicng.knowledgecompilation.bdds.jbuddy.BDDKernel)1 BDDOperations (org.logicng.knowledgecompilation.bdds.jbuddy.BDDOperations)1