Example #1
0
    public void MakeNot()
    {
        var obdd = new OBDD();

        var a = obdd.MakeLiteral(0);
        var b = obdd.MakeLiteral(1);

        Assert.IsNotNull(a);
        Assert.IsNotNull(b);
        Assert.AreNotEqual(a, b);

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

        Assert.IsNotNull(na);
        Assert.IsNotNull(nb);
        Assert.AreNotEqual(na, nb);
        Assert.AreNotEqual(a, na);
        Assert.AreNotEqual(b, nb);

        var nna = obdd.MakeNot(na);
        var nnb = obdd.MakeNot(nb);

        Assert.IsNotNull(nna);
        Assert.IsNotNull(nnb);
        Assert.AreNotEqual(nna, nnb);

        // double negation cancels out
        Assert.AreEqual(a, nna);
        Assert.AreEqual(b, nnb);
    }
Example #2
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 #3
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);
    }