Exemplo n.º 1
0
        private void HandlePredicateDefine(PlanningParser.PredicateDefineContext context)
        {
            _exclusiveAxiom = CUDD.Constant(1);
            _predicateDict  = new Dictionary <string, Predicate>();
            foreach (var atomFormSkeleton in context.atomFormSkeleton())
            {
                PredicateEnumerator enumerator = new PredicateEnumerator(atomFormSkeleton, _predicateDict, _currentCuddIndex);
                Algorithms.IterativeScanMixedRadix(enumerator);
                _currentCuddIndex = enumerator.CurrentCuddIndex;

                if (atomFormSkeleton.oneofDefine() != null)
                {
                    Console.WriteLine("Predicate {0} have oneOf", atomFormSkeleton.predicate().GetText());
                    //Console.WriteLine("Hello!");
                    //Console.ReadLine();
                    string           predicateName         = atomFormSkeleton.predicate().GetText();
                    int              oneOfVarsCount        = atomFormSkeleton.oneofDefine().VAR().Count;
                    string[]         oneOfVarNameArray     = new string[oneOfVarsCount];
                    var              varNameList           = atomFormSkeleton.listVariable().GetVariableNameList();
                    var              collection            = atomFormSkeleton.listVariable().GetCollection();
                    IList <string>[] notOneOfVarCollection = new IList <string> [varNameList.Count - oneOfVarsCount];

                    Parallel.For(0, oneOfVarsCount,
                                 i => oneOfVarNameArray[i] = atomFormSkeleton.oneofDefine().VAR(i).GetText());

                    for (int i = 0, k = 0; i < varNameList.Count; i++)
                    {
                        bool exists = oneOfVarNameArray.Any(s => s == varNameList[i]);

                        if (!exists)
                        {
                            notOneOfVarCollection[k] = collection[i];
                            k++;
                            if (k == notOneOfVarCollection.Length)
                            {
                                break;
                            }
                        }
                    }

                    ExclusiveAxiomEnumerator exclusiveAxiomEnumerator = new ExclusiveAxiomEnumerator(predicateName,
                                                                                                     _predicateDict, notOneOfVarCollection);
                    Algorithms.IterativeScanMixedRadix(exclusiveAxiomEnumerator);
                    _exclusiveAxiom = CUDD.Function.And(_exclusiveAxiom, exclusiveAxiomEnumerator.ExclusiveAxiom);
                }
            }

            //foreach (var predicate in _predicateDict.Values)
            //{
            //    Console.WriteLine("name: {0}, Previous index: {1}, successive index: {2}", predicate.FullName, predicate.PreviousCuddIndex, predicate.SuccessiveCuddIndex);
            //}
        }
Exemplo n.º 2
0
        private void HandlePredicateDefine(PlanningParser.PredicateDefineContext context)
        {
            _predicateDict = new Dictionary <string, Predicate>();
            //_predicateExclusiveAxiom = new Dictionary<string, CUDDNode>();
            foreach (var atomFormSkeleton in context.atomFormSkeleton())
            {
                PredicateEnumerator enumerator = new PredicateEnumerator(atomFormSkeleton, _predicateDict, _currentCuddIndex);
                Algorithms.IterativeScanMixedRadix(enumerator);
                _currentCuddIndex = enumerator.CurrentCuddIndex;

                //string predicateName = atomFormSkeleton.predicate().GetText();

                //_predicateExclusiveAxiom.Add();
            }

            //foreach (var predicate in _predicateDict.Values)
            //{
            //    Console.WriteLine("name: {0}, Previous index: {1}, successive index: {2}", predicate.FullName, predicate.PreviousCuddIndex, predicate.SuccessiveCuddIndex);
            //}
            //Console.ReadLine();
        }
Exemplo n.º 3
0
        ExecutionResults Step()
        {
            switch (State)
            {
            case WamMachineStates.Backtrack:
                if (Backtrack())
                {
                    State = WamMachineStates.Run;
                    return(ExecutionResults.None);
                }
                State = WamMachineStates.Halt;
                return(ExecutionResults.Failure);

            case WamMachineStates.Halt:
                return(ExecutionResults.Failure);

            case WamMachineStates.Run:

                ExecutionResults results;
                if (PredicateEnumerator != null)
                {
                    if (PredicateEnumerator.MoveNext() == false)
                    {
                        ChoicePoint = ChoicePoint.Predecessor;
                        results     = ExecutionResults.Backtrack;
                    }
                    else
                    {
                        results = ExecutionResults.None;
                    }
                    PredicateEnumerator = null;
                }
                else
                {
                    var instruction = InstructionPointer.Instruction;
                    results = Execute(instruction);
                }

                switch (results)
                {
                case ExecutionResults.None:
                    // No action required
                    break;

                case ExecutionResults.Backtrack:
                    State = WamMachineStates.Backtrack;
                    break;

                case ExecutionResults.Success:
                    State = WamMachineStates.Backtrack;
                    break;

                case ExecutionResults.Failure:
                    State = WamMachineStates.Halt;
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Unknown execution result {0}.", results));
                }
                return(results);

            default:
                throw new InvalidOperationException(string.Format("Unknown state {0}.", State));
            }
        }