Example #1
0
    public void Example()
    {
        // f(a,b,c) = (!a & !b & !c) | (a & b) | (b & c)
        var obdd = new OBDD();

        var a = obdd.MakeNode(0, BDDNode.True, BDDNode.False);
        var b = obdd.MakeNode(1, BDDNode.True, BDDNode.False);
        var c = obdd.MakeNode(2, BDDNode.True, BDDNode.False);

        var na = obdd.MakeNot(a);
        var nb = obdd.MakeNot(b);
        var nc = obdd.MakeNot(c);

        var tmpAnd = obdd.MakeAnd(na, nb);
        var and1   = obdd.MakeAnd(tmpAnd, nc);
        var and2   = obdd.MakeAnd(a, b);
        var and3   = obdd.MakeAnd(b, c);

        var tmpOr = obdd.MakeOr(and1, and2);
        var or    = obdd.MakeOr(tmpOr, and3);

        var root = or;

        using (var writer = new StringWriter())
        {
            root.ExportToGraphviz(writer);
            Debug.Log(writer);
        }
    }
Example #2
0
    private static BDDNode AddTransition(OBDD obdd, BDDNode node, int index, int numBits, int offset)
    {
        for (int i = 0; i < numBits; i++)
        {
            int literal  = i * 2 + offset;
            var variable = obdd.MakeLiteral(literal);

            bool hasBit = (index & (1 << i)) != 0;
            if (!hasBit)
            {
                variable = obdd.MakeNot(variable);
            }

            node = obdd.MakeAnd(node, variable);
        }

        return(node);
    }