public bool ValidatePlan(PartiallySpecifiedState pssCurrent)
        {
            if (pssCurrent == null)
            {
                return(false);
            }
            if (pssCurrent.IsGoalState())
            {
                return(true);
            }

            if (Action == null)
            {
                return(false);
            }
            Formula fObserved = null;
            PartiallySpecifiedState psTrueState, psFalseState;

            pssCurrent.ApplyOffline(Action, out fObserved, out psTrueState, out psFalseState);
            if (Action.Observe == null)
            {
                return(SingleChild.ValidatePlan(psTrueState));
            }
            bool bTrueOk  = TrueObservationChild.ValidatePlan(psTrueState);
            bool bFalseOk = FalseObservationChild.ValidatePlan(psFalseState);

            return(bTrueOk && bFalseOk);
        }
Пример #2
0
        private List <PartiallySpecifiedState> SearchAllStates(Domain domain, List <PartiallySpecifiedState> lInitialStates)
        {
            Console.WriteLine("Scanning all possible states, using BFS algorithm");
            Formula fObserved = null;
            PartiallySpecifiedState         fTrueObserved         = null;
            PartiallySpecifiedState         fFalseObserved        = null;
            Stack <PartiallySpecifiedState> OpenListStack         = new Stack <PartiallySpecifiedState>(lInitialStates);
            Dictionary <string, PartiallySpecifiedState> OpenList = new Dictionary <string, PartiallySpecifiedState>();

            foreach (PartiallySpecifiedState pss in OpenListStack)
            {
                OpenList.Add(pss.ToString(), pss);
            }

            Dictionary <string, PartiallySpecifiedState> ClosedList = new Dictionary <string, PartiallySpecifiedState>();
            List <IMAP.Action> groundedActions = domain.GroundAllActions(domain.Actions, domain.GroundAllPredicates(null), false, false);


            int iterationCounter = 0;

            while (OpenListStack.Count != 0)
            {
                if (iterationCounter++ % 100 == 0)
                {
                    Console.WriteLine("Seaching: (OL=" + OpenListStack.Count + "/CL=" + ClosedList.Count + ")");
                }
                PartiallySpecifiedState selectedState = OpenListStack.Pop();
                OpenList.Remove(selectedState.ToString());

                ClosedList.Add(selectedState.ToString(), selectedState);

                foreach (var a in groundedActions)
                {
                    selectedState.ApplyOffline(a, out fObserved, out fTrueObserved, out fFalseObserved);

                    if (fTrueObserved != null && fTrueObserved.GetPositivePredicates().Count != selectedState.GetPositivePredicates().Count)
                    {
                        continue;
                    }
                    if (fTrueObserved != null)
                    {
                        if (ClosedList.ContainsKey(fTrueObserved.ToString()) || OpenList.ContainsKey(fTrueObserved.ToString()))
                        {
                            continue;
                        }

                        OpenListStack.Push(fTrueObserved);
                        OpenList.Add(fTrueObserved.ToString(), fTrueObserved);
                    }
                }
            }
            return(ClosedList.Values.ToList());
        }
Пример #3
0
        private static bool CheckPlansOnSingleInitialState(PartiallySpecifiedState initialState, Dictionary <Constant, PlanResult> plans, List <Predicate> goals)
        {
            List <Action>           actionsList        = GenerateJointActionsListForSingleInitialState(initialState, plans);
            List <Predicate>        collectedPredicate = new List <Predicate>();
            PartiallySpecifiedState currentState       = initialState.Clone();

            foreach (var action in actionsList)
            {
                currentState.ApplyOffline(action, out Formula obs, out PartiallySpecifiedState psTrue, out PartiallySpecifiedState psFalse);
                currentState = psTrue;
            }
            if (currentState.IsGoalState())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }