private void ReadParameters(CompoundExpression exp, ParametrizedAction pa)
        {
            int iExpression = 0;

            //unfortunately, expressions have a weird non standard structure with no type - (?i - pos ?j - pos )
            //so we must have a special case for the first parameter
            if (exp.SubExpressions.Count == 0 || exp.SubExpressions[0].ToString()[0] == '?')//no types
            {
                string sName = exp.Type;
                pa.AddParameter(new Parameter("OBJ", sName));
                for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
                {
                    sName = exp.SubExpressions[iExpression].ToString();
                    pa.AddParameter(new Parameter("OBJ", sName));
                }
            }
            else//types for expressions
            {
                string sName = exp.Type, sType = exp.SubExpressions[1].ToString();
                pa.AddParameter(new Parameter(sType, sName));
                for (iExpression = 2; iExpression < exp.SubExpressions.Count; iExpression += 3)
                {
                    sName = exp.SubExpressions[iExpression].ToString();
                    sType = exp.SubExpressions[iExpression + 2].ToString();
                    if (exp.SubExpressions[iExpression + 1].ToString() != "-")
                    {
                        throw new InvalidDataException("Expression " + exp + " has the wrong format");
                    }
                    pa.AddParameter(new Parameter(sType, sName));
                }
            }
        }
        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);
        }
示例#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);
        }