Ejemplo n.º 1
0
        public static Tuple <Predicate, bool> GetLiteral(this PlanningParser.TermLiteralContext context,
                                                         IReadOnlyDictionary <string, Predicate> predicateDict, StringDictionary assignment)
        {
            string    fullName   = ConstContainer.GetFullName(context.termAtomForm(), assignment);
            Predicate predicate  = predicateDict[fullName];
            bool      isPositive = context.NOT() == null;

            return(new Tuple <Predicate, bool>(predicate, isPositive));
        }
Ejemplo n.º 2
0
        private static CUDDNode GetCuddNode(PlanningParser.TermEventFormContext context, IReadOnlyDictionary <string, Event> eventDict, StringDictionary assignment)
        {
            CUDDNode result;

            if (context.eventSymbol() != null)
            {
                string eventFullName = ConstContainer.GetFullName(context, assignment);
                if (eventDict.ContainsKey(eventFullName))
                {
                    Event e         = eventDict[eventFullName];
                    int   cuddIndex = e.CuddIndex;
                    result = CUDD.Var(cuddIndex);
                }
                else
                {
                    result = CUDD.ZERO;
                    CUDD.Ref(result);
                }
            }
            else
            {
                string firstTermString  = Globals.TermInterpreter.GetString(context.term(0), assignment);
                string secondTermString = Globals.TermInterpreter.GetString(context.term(1), assignment);
                if (context.EQ() != null)
                {
                    result = firstTermString == secondTermString ? CUDD.ONE : CUDD.ZERO;
                }
                else if (context.NEQ() != null)
                {
                    result = firstTermString != secondTermString ? CUDD.ONE : CUDD.ZERO;
                }
                else
                {
                    int firstValue  = int.Parse(firstTermString);
                    int secondValue = int.Parse(secondTermString);
                    if (context.LT() != null)
                    {
                        result = firstValue < secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else if (context.LEQ() != null)
                    {
                        result = firstValue <= secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else if (context.GT() != null)
                    {
                        result = firstValue > secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else
                    {
                        result = firstValue >= secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                }
                CUDD.Ref(result);
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static CUDDNode GetCuddNode(this PlanningParser.TermAtomFormContext context,
                                            IReadOnlyDictionary <string, Predicate> predicateDict, StringDictionary assignment)
        {
            CUDDNode result;

            if (context.predicate() != null)
            {
                string    predicateFullName = ConstContainer.GetFullName(context, assignment);
                Predicate predicate         = predicateDict[predicateFullName];
                int       cuddIndex         = predicate.PreviousCuddIndex;
                result = CUDD.Var(cuddIndex);
            }
            else
            {
                string firstTermString  = Globals.TermInterpreter.GetString(context.term(0), assignment);
                string secondTermString = Globals.TermInterpreter.GetString(context.term(1), assignment);
                if (context.EQ() != null)
                {
                    result = firstTermString == secondTermString ? CUDD.ONE : CUDD.ZERO;
                }
                else if (context.NEQ() != null)
                {
                    result = firstTermString != secondTermString ? CUDD.ONE : CUDD.ZERO;
                }
                else
                {
                    int firstValue  = int.Parse(firstTermString);
                    int secondValue = int.Parse(secondTermString);
                    if (context.LT() != null)
                    {
                        result = firstValue < secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else if (context.LEQ() != null)
                    {
                        result = firstValue <= secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else if (context.GT() != null)
                    {
                        result = firstValue > secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                    else
                    {
                        result = firstValue >= secondValue ? CUDD.ONE : CUDD.ZERO;
                    }
                }
                CUDD.Ref(result);
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void HandleInit(PlanningParser.InitContext context)
        {
            TruePredSet = new HashSet <string>();
            foreach (var atomForm in context.constTermAtomForm())
            {
                var      constTermContexts = atomForm.constTerm();
                int      count             = constTermContexts.Count;
                string[] termArray         = new string[count];
                Parallel.For(0, count, i => termArray[i] = constTermContexts[i].GetText());

                string predicateFullname = ConstContainer.GetFullName(atomForm.predicate().GetText(), termArray);

                TruePredSet.Add(predicateFullname);
            }
        }
Ejemplo n.º 5
0
        public Action GetAction()
        {
            byte[] contentBuffer = ReceiveBuffer();
            int    index         = Array.FindIndex(contentBuffer, b => b == (byte)'(');

            char[] actionNameChars = new char[index];
            Parallel.For(0, index, i => actionNameChars[i] = (char)contentBuffer[i]);
            string actionName = new string(actionNameChars);

            List <string> constantList = new List <string>();

            int parmFromInclusive = index + 1;
            int parmToExclusive   = Array.FindIndex(contentBuffer, parmFromInclusive,
                                                    b => b == (byte)',' || b == (byte)')');

            while (parmToExclusive != -1)
            {
                if (contentBuffer[parmToExclusive - 1] != (byte)'(')
                {
                    char[] parmChars = new char[parmToExclusive - parmFromInclusive];
                    Parallel.For(parmFromInclusive, parmToExclusive,
                                 i => parmChars[i - parmFromInclusive] = (char)contentBuffer[i]);
                    string parm = new string(parmChars);
                    constantList.Add(parm);
                    parmFromInclusive = parmToExclusive + 1;
                    parmToExclusive   = Array.FindIndex(contentBuffer, parmFromInclusive,
                                                        b => b == (byte)',' || b == (byte)')');
                    continue;
                }
                break;
            }

            string actionFullName = ConstContainer.GetFullName(actionName, constantList.ToArray());

            return(_actionDict[actionFullName]);
        }
Ejemplo n.º 6
0
 public Action(PlanningParser.ProgramContext context)
 {
     FullName = ConstContainer.GetFullName(context.actionSymbol(), context.term());
 }