Exemple #1
0
        public List <Action> GenActions(Conjunction thePre)
        {
            List <Action> actions = new List <Action>();

            foreach (Operator op in m_ops)
            {
                List <Action> temp = op.GenActions(thePre);
                if (temp != null)
                {
                    actions.AddRange(temp);
                }
            }
            return(actions);
        }
Exemple #2
0
        //public Action()
        //{
        //    this.m_preCondition = new Conjunction();
        //    this.m_addEffects = new Conjunction();
        //    this.m_delEffects = new Conjunction();

        //    this.m_preEdges = new List<Proposition>();
        //    this.m_addProps = new List<Proposition>();
        //    this.m_delProps = new List<Proposition>();
        //}

        public Action(string h, string pre, string add, string del)
        {
            this.m_head         = h;
            this.m_preCondition = new Conjunction(pre);
            this.m_addEffects   = new Conjunction(add);
            this.m_delEffects   = new Conjunction(del);

            this.m_preEdges = new List <Proposition>();
            this.m_addProps = new List <Proposition>();
            this.m_delProps = new List <Proposition>();

            // foamliu, 2009/01/22, 与本 action 互斥的 actions.
            this.m_mutexActions = new List <Action>();
        }
Exemple #3
0
        /// <summary>
        /// foamliu, 2009/01/21, 添加 No-op actions.
        /// </summary>
        private void AddNoops()
        {
            Conjunction conj = m_prev.Conjunction;

            foreach (string s in conj.Literals)
            {
                // 创建 No-op action.
                Action theAct = new Action("NOOP: " + s);
                theAct.PreCondition.Literals.Add(s);
                theAct.AddEffects.Literals.Add(s);
                this.m_actions.Add(theAct);
                // 把这个 no-op 加入当前行为层.
                Proposition theProp = m_prev.GetProposition(s);
                theProp.AddPreEdge(theAct);
                theAct.AddPreProp(theProp);
                // 把这个命题加入下个命题层.
                theProp = m_next.AddProposition(s);
                theProp.AddAddEdge(theAct);
                theAct.AddAddProp(theProp);
            }
        }
Exemple #4
0
        /// <summary>
        /// foamliu, 2009/01/20.
        /// 是否相同的合取, 顺序不重要.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Conjunction))
            {
                return(false);
            }
            Conjunction theCnj = (Conjunction)obj;

            if (theCnj.Literals.Count != this.Literals.Count)
            {
                return(false);
            }

            foreach (string item in theCnj.Literals)
            {
                if (!this.Literals.Contains(item))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #5
0
        /// <summary>
        /// foamliu, 2009/01/21, 替换合取式中的变量.
        /// 比如, conj为:
        ///     ON (?obj, ?from) & Clear (?obj) & Clear (?to)
        /// un为:
        ///  * --------------------------
        ///  *   var      |  value
        ///  * --------------------------
        ///  *   ?obj	  |  b1
        ///  *   ?from	  |  b2
        ///  *   ?to      |  b3
        ///  * --------------------------
        ///  则返回:
        ///     ON (b1, b2) & Clear (b1) & Clear (b3)
        ///
        /// </summary>
        /// <param name="conj"></param>
        /// <param name="un"></param>
        /// <returns></returns>
        public static string Substitute(Conjunction conj, Unifier un)
        {
            //StringBuilder sb = new StringBuilder();

            //foreach (string literal in conj.Literals)
            //{
            //    string[] tokens = Util.Split(literal);
            //    foreach (string token in tokens)
            //    {
            //        if (token.StartsWith("?"))
            //        {
            //            // 是变量, 取对应值.
            //            sb.Append(un.Get(token));
            //        }
            //        else
            //        {
            //            // 不是变量, 直接加上去.
            //            sb.Append(token);
            //        }
            //    }

            //    sb.Append(" & ");
            //}

            //// 去掉结尾的 " & ".
            //string s = sb.ToString();
            //return s.Substring(0, s.Length - 3);

            string s = conj.ToString();

            foreach (string var in un.Table.Keys)
            {
                string val = un.Table[var];
                s = s.Replace(var, val);
            }

            return(s);
        }
Exemple #6
0
        /// <summary>
        /// foamliu, 2009/01/20.
        /// 找到所有这样的 actions: 它们的 Preconditions 在 thePre 里.
        ///
        /// </summary>
        /// <param name="thePre"></param>
        /// <returns></returns>
        public List <Action> GenActions(Conjunction thePre)
        {
            List <Action> actions = new List <Action>();
            List <string> vars    = m_opHead.ParaList.Vars;

            foreach (string s in m_validUnifiers)
            {
                Unifier     un   = new Unifier(vars, s);
                string      aPre = Util.Substitute(m_pre, un);
                Conjunction conj = new Conjunction(aPre);

                if (thePre.Contains(conj))
                {
                    // 创建一个 action
                    string aHead = Util.Substitute(m_opHead, un);
                    string aAdd  = Util.Substitute(m_add, un);
                    string aDel  = Util.Substitute(m_del, un);

                    actions.Add(new Action(aHead, aPre, aAdd, aDel));
                }
            }

            return(actions);
        }
Exemple #7
0
 public GraphPlan()
 {
     this.m_objects  = new EntitySet();
     this.m_initials = new Conjunction();
     this.m_goal     = new Conjunction();
 }
Exemple #8
0
 public PropositionLayer()
 {
     this.m_props = new List <Proposition>();
     this.m_dict  = new Dictionary <string, Proposition>();
     this.m_conj  = new Conjunction();
 }