Ejemplo n.º 1
0
        private void AddKnowledgePredicatesToExistingActions(Domain d, List <Predicate> lKnowPredicates)
        {
            Actions = new List <Action>();
            ParametrizedAction aRevised = null;

            foreach (Action a in d.Actions)
            {
                aRevised = new ParametrizedAction(a.Name);
                aRevised.Preconditions = AddKnowledgePredicatesToFormula(a.Preconditions, lKnowPredicates);
                CompoundFormula cfEffects = null;
                if (a.Effects != null)
                {
                    cfEffects = AddKnowledgePredicatesToFormula(a.Effects, lKnowPredicates);
                }
                else
                {
                    cfEffects = new CompoundFormula("and");
                }
                if (a.Observe != null)
                {
                    List <Predicate> lPredicates = GetAllPredicates(a.Observe);
                    foreach (Predicate p in lPredicates)
                    {
                        cfEffects.AddOperand(new PredicateFormula(new KnowPredicate(p)));
                    }
                }
                aRevised.SetEffects(cfEffects);
                Actions.Add(aRevised);
            }
        }
Ejemplo n.º 2
0
        private Action ReadAction(CompoundExpression exp, Domain d)
        {
            string sName       = exp.SubExpressions[0].ToString();
            Action pa          = null;
            int    iExpression = 0;

            for (iExpression = 1; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                if (exp.SubExpressions[iExpression].ToString() == ":parameters")
                {
                    CompoundExpression ceParams = (CompoundExpression)exp.SubExpressions[iExpression + 1];
                    if (ceParams.Type != "N/A")
                    {
                        pa = new ParametrizedAction(sName);
                        ReadParameters((CompoundExpression)exp.SubExpressions[iExpression + 1], (ParametrizedAction)pa);
                    }
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":effect")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadEffect((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":precondition")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadPrecondition((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":observe")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadObserve((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
            }
            return(pa);
        }
Ejemplo n.º 3
0
        public override Action Clone()
        {
            ParametrizedAction aNew = new ParametrizedAction(Name);

            aNew.Parameters = Parameters;
            if (Preconditions != null)
            {
                aNew.Preconditions = Preconditions.Clone();
            }
            if (Effects != null)
            {
                aNew.SetEffects(Effects.Clone());
            }
            if (Observe != null)
            {
                aNew.Observe = Observe.Clone();
            }
            aNew.HasConditionalEffects          = HasConditionalEffects;
            aNew.ContainsNonDeterministicEffect = ContainsNonDeterministicEffect;
            return(aNew);
        }
Ejemplo n.º 4
0
        private void ReadParameters(CompoundExpression exp, ParametrizedAction pa)
        {
            //unfortunately, expressions have a weird non standard structure with no type - (?i - pos ?j - pos )
            //so we must have a special case
            List <string> lTokens  = exp.ToTokenList();
            List <string> lNames   = new List <string>();
            string        sType    = "";
            int           iCurrent = 0;

            while (iCurrent < lTokens.Count)
            {
                if (lTokens[iCurrent] == "-")
                {
                    sType = lTokens[iCurrent + 1];
                    foreach (string sName in lNames)
                    {
                        pa.AddParameter(new Parameter(sType, sName));
                    }
                    lNames    = new List <string>();
                    sType     = "";
                    iCurrent += 2;
                }
                else
                {
                    lNames.Add(lTokens[iCurrent]);
                    iCurrent++;
                }
            }
            if (lNames.Count != 0) //allowing no types specified
            {
                foreach (string sName in lNames)
                {
                    pa.AddParameter(new Parameter("OBJ", sName));
                }
            }
        }