コード例 #1
0
        //returns true if operand already exists
        public bool AddOperand(Formula f)
        {
            m_sCachedToString = null;
            if (f == null)
                return false;
            if (Size > 20 || f.Size > 20)
            {
                SimpleAddOperand(f);
                return false;
            }
            if (Operator == "when")
            {
                if (Operands.Count < 2)
                {
                    Operands.Add(f);
                    Size += f.Size;
                }
                else
                    throw new NotImplementedException();
                return false;
            }
            if (Operands.Contains(f))
                return true;
            if (f is ParametrizedFormula)//for universal quantifiers, assuming for now that they were not added before
            {
                Operands.Add(f);
                Size += f.Size;
                return false;
            }
            if (f is ProbabilisticFormula)
            {
                Operands.Add(f);
                Size += f.Size;
                return false;
            }
            if (f is PredicateFormula)
            {
                Predicate p = ((PredicateFormula)f).Predicate;
                if (p.Name == Domain.TRUE_PREDICATE)
                    if (Operator == "and")
                        return false;
                if (p.Name == Domain.FALSE_PREDICATE)
                    if (Operator == "or")
                        return false;
            }
            if( f is CompoundFormula && ((CompoundFormula)f).Operator == Operator)
            {
                bool bContainsAll = true;
                foreach (Formula fOperand in ((CompoundFormula)f).Operands)
                {
                    if (!AddOperand(fOperand))
                        bContainsAll = false;
                    else
                        Size += fOperand.Size;
                }
                return bContainsAll;
            }
            if (f is CompoundFormula)
            {
                CompoundFormula cf = (CompoundFormula)f;
                if (cf.Operands.Count == 1)
                {
                    Size += cf.Operands[0].Size;
                    return AddOperand(cf.Operands[0]);
                }
            }
            Simplified = false;
            if (f is CompoundFormula && ((CompoundFormula)f).Operator == "oneof")
            {
                Size += f.Size;
                Operands.Add(f);//don't know how to negate oneof for now
                return false;
            }
            else
            {

                if (Operator != "oneof" && Operands.Contains(f.Negate()))
                {
                    if (Operator == "and")
                        Operands.Add(new PredicateFormula(new GroundedPredicate(Domain.FALSE_PREDICATE)));
                    else if (Operator == "or")
                        Operands.Add(new PredicateFormula(new GroundedPredicate(Domain.TRUE_PREDICATE)));
                    else
                        throw new NotImplementedException();
                    Operands.Remove(f.Negate());
                    return true;
                }
                else
                {
                    Size += f.Size;
                    Operands.Add(f);
                    return false;
                }
            }
            return true;
        }
コード例 #2
0
        //used to regress goal or precondition
        public bool RegressCondition(Formula f)
        {
            PartiallySpecifiedState pssCurrent = this;
            Formula fCurrent = f.Negate();
            while (pssCurrent != null)
            {
                Formula fReduced = fCurrent.Reduce(pssCurrent.Observed);
                if (fReduced.IsTrue(null))
                    return false;
                if (fReduced.IsFalse(null))
                    return true;
                if (pssCurrent.Predecessor != null)
                {
                    if (pssCurrent.GeneratingAction.HasConditionalEffects)
                    {
                        Formula fRegressed = fReduced.Regress(pssCurrent.GeneratingAction);
                        fCurrent = fRegressed;
                    }
                }
                pssCurrent = pssCurrent.Predecessor;

            }
            return !m_bsInitialBelief.ConsistentWith(fCurrent);
        }