示例#1
0
        private Action CreateReasoningAction(Predicate pEffect, HashSet <Predicate> lPredicates)
        {
            KnowPredicate kpEffect = new KnowPredicate(pEffect);

            if (Predicates.Contains(kpEffect))
            {
                return(null);
            }
            Action a = new KnowledgeAction("Reasoning_" + pEffect.ToString());

            a.Preconditions = new CompoundFormula("and");
            foreach (Predicate pOther in lPredicates)
            {
                if (pOther != pEffect)
                {
                    KnowPredicate kp = new KnowPredicate(pOther);
                    if (!Predicates.Contains(kp))
                    {
                        return(null);
                    }
                    ((CompoundFormula)a.Preconditions).AddOperand(new PredicateFormula(kp));
                }
            }
            CompoundFormula cfEffects = new CompoundFormula("and");

            cfEffects.AddOperand(new PredicateFormula(kpEffect));
            a.SetEffects(cfEffects);
            return(a);
        }
示例#2
0
        private void AddKnowledgePredicatesToExistingActions(HashSet <Predicate> lKnowPredicates)
        {
            List <Action> lActions = AvailableActions;

            AvailableActions = new List <Action>();
            foreach (Action a in lActions)
            {
                KnowledgeAction ka = new KnowledgeAction(a);
                ka.Preconditions = AddKnowledgePredicatesToFormula(a.Preconditions, lKnowPredicates);
                CompoundFormula cfEffects = null;
                if (Contains(ka.Preconditions))
                {
                    if (a.Effects != null)
                    {
                        cfEffects = AddKnowledgePredicatesToFormula(a.Effects, lKnowPredicates);
                    }
                    else
                    {
                        cfEffects = new CompoundFormula("and");
                    }
                    if (a.Observe != null)
                    {
                        HashSet <Predicate> lPredicates = new HashSet <Predicate>();
                        a.Observe.GetAllPredicates(lPredicates);
                        foreach (Predicate p in lPredicates)
                        {
                            cfEffects.AddOperand(new PredicateFormula(new KnowPredicate(p)));
                        }
                        ka.Observe = null;
                    }
                    ka.SetEffects(cfEffects);
                    if (!Contains(ka.Effects))
                    {
                        AvailableActions.Add(ka);
                    }
                }
            }
        }