Beispiel #1
0
        private CUDDNode GetCuddNode(PlanningParser.GdContext context)
        {
            CUDDNode result = null;

            if (context.atomicFormulaTerm() != null)
            {
                result = GetCuddNode(context.atomicFormulaTerm());
            }
            else if (context.literalTerm() != null)
            {
                result = GetCuddNode(context.literalTerm());
            }
            else if (context.AND() != null)
            {
                result = GetCuddNode(context.gd()[0]);
                for (int i = 1; i < context.gd().Count; i++)
                {
                    CUDDNode gdNode  = GetCuddNode(context.gd()[i]);
                    CUDDNode andNode = CUDD.Function.And(result, gdNode);
                    CUDD.Ref(andNode);
                    CUDD.Deref(result);
                    CUDD.Deref(gdNode);
                    result = andNode;
                }
            }
            else if (context.OR() != null)
            {
                result = GetCuddNode(context.gd()[0]);
                for (int i = 1; i < context.gd().Count; i++)
                {
                    CUDDNode gdNode = GetCuddNode(context.gd()[i]);
                    CUDDNode orNode = CUDD.Function.Or(result, gdNode);
                    CUDD.Ref(orNode);
                    CUDD.Deref(result);
                    CUDD.Deref(gdNode);
                    result = orNode;
                }
            }
            else if (context.NOT() != null)
            {
                CUDDNode gdNode = GetCuddNode(context.gd()[0]);
                result = CUDD.Function.Not(gdNode);
                CUDD.Ref(result);
                CUDD.Deref(gdNode);
            }
            else if (context.IMPLY() != null)
            {
                CUDDNode gdNode0 = GetCuddNode(context.gd()[0]);
                CUDDNode gdNode1 = GetCuddNode(context.gd()[1]);

                result = CUDD.Function.Implies(gdNode0, gdNode1);
                CUDD.Ref(result);
                CUDD.Deref(gdNode0);
                CUDD.Deref(gdNode1);
            }

            return(result);
        }
Beispiel #2
0
        public static CUDDNode GetCuddNode(this PlanningParser.GdContext context,
                                           IReadOnlyDictionary <string, Predicate> predicateDict, StringDictionary assignment)
        {
            CUDDNode result;

            if (context.termAtomForm() != null)
            {
                result = GetCuddNode(context.termAtomForm(), predicateDict, assignment);
            }
            else if (context.AND() != null)
            {
                var gdContextList = context.gd();
                result = GetCuddNode(gdContextList[0], predicateDict, assignment);

                if (!result.Equals(CUDD.ZERO))
                {
                    for (int i = 1; i < gdContextList.Count; i++)
                    {
                        CUDDNode gdNode = GetCuddNode(gdContextList[i], predicateDict, assignment);
                        if (gdNode.Equals(CUDD.ZERO))
                        {
                            CUDD.Deref(result);
                            result = CUDD.ZERO;
                            CUDD.Ref(result);
                            break;
                        }
                        result = CUDD.Function.And(result, gdNode);
                    }
                }
            }
            else if (context.OR() != null)
            {
                var gdContextList = context.gd();
                result = GetCuddNode(gdContextList[0], predicateDict, assignment);

                if (!result.Equals(CUDD.ONE))
                {
                    for (int i = 1; i < gdContextList.Count; i++)
                    {
                        CUDDNode gdNode = GetCuddNode(gdContextList[i], predicateDict, assignment);
                        if (gdNode.Equals(CUDD.ONE))
                        {
                            CUDD.Deref(result);
                            result = CUDD.ONE;
                            CUDD.Ref(result);
                            break;
                        }
                        result = CUDD.Function.Or(result, gdNode);
                    }
                }
            }
            else if (context.NOT() != null)
            {
                CUDDNode gdNode = GetCuddNode(context.gd()[0], predicateDict, assignment);
                result = CUDD.Function.Not(gdNode);
            }
            else if (context.IMPLY() != null)
            {
                var      gdContextList = context.gd();
                CUDDNode gdNode0       = GetCuddNode(gdContextList[0], predicateDict, assignment);
                CUDDNode gdNode1       = GetCuddNode(gdContextList[1], predicateDict, assignment);
                result = CUDD.Function.Implies(gdNode0, gdNode1);
            }
            else
            {
                var  listVariableContext = context.listVariable();
                var  collection          = listVariableContext.GetCollection();
                var  varNameList         = listVariableContext.GetVariableNameList();
                bool isForall            = context.FORALL() != null;
                result = RecursiveScanMixedRaio(context.gd(0), predicateDict, varNameList, collection, assignment, 0, isForall);
            }

            return(result);
        }