/// <summary> /// foamliu, 2009/01/19, 扩展规划图. /// /// Expand the planning graph, one action layer and one proposition layer at a time. /// /// </summary> private bool ExpandGraph() { for (int i = 1; i <= MaxLevel; i++) { // 创建 Ai 和 Pi+1 List <Action> actions = this.m_operators.GenActions(this.m_lastProp.Conjunction); ActionLayer aLayer = new ActionLayer(this.m_lastProp, actions); aLayer.Number = this.m_lastProp.Number; this.m_lastProp.NextLayer = aLayer; this.m_lastProp = aLayer.NextLayer; this.m_lastProp.Number = aLayer.Number + 1; if (GoalsReachable()) { return(true); } // 测试是否 Level Off if (LevelOff()) { System.Console.WriteLine("Graph Levels Off at level" + m_lastProp.Number); return(false); } } System.Console.WriteLine("到达了预设的最大 Level:" + MaxLevel); return(false); }
/// <summary> /// foamliu, 2009/01/19, 初始化规划图. /// </summary> private void InitGraph() { // 初始条件构成第一个命题层: P1. this.m_firstProp = new PropositionLayer(); this.m_firstProp.SetInitLayer(this.m_initials); // 参见类头注释. this.m_firstProp.Number = 1; this.m_lastProp = this.m_firstProp; }
/// <summary> /// foamliu, 2009/01/19. /// /// 如果一直找不到有效的规划, 则最后会到达一个命题层 P, 之后所有的命题层都与它完全相同. /// 原因: 由于 No-Op actions 的存在, 一个命题出现在某个命题层中, 则它也必然出现在后续的命题层中. /// 也就是命题层中命题数量是单调递增的, 而在命题有限的情况下又是有界的, 所以必然会有最大值. /// /// 这个条件可以作为图扩展的结束测试. /// </summary> /// <returns></returns> private bool LevelOff() { PropositionLayer p = this.m_lastProp; ActionLayer act = p.PrevLayer; if (!p.Equals(act.PrevLayer)) { return(false); } return(true); }
/// <summary> /// foamliu, 2009/01/22, for debug use. /// </summary> /// <returns></returns> public override string ToString() { StringBuilder sb = new StringBuilder(); PropositionLayer pLayer = m_firstProp; ActionLayer aLayer; while (pLayer != null) { sb.Append(pLayer.ToString()); aLayer = pLayer.NextLayer; if (aLayer != null) { sb.Append(aLayer.ToString()); pLayer = aLayer.NextLayer; } else { pLayer = null; } } return(sb.ToString()); }
//public ActionLayer() //{ //} /// <summary> /// foamliu, 2009/01/21. /// </summary> /// <param name="prev"></param> /// <param name="acts"></param> public ActionLayer(PropositionLayer prev, List <Action> acts) { this.m_actions = new List <Action>(); this.m_selectedActions = new List <Action>(); this.m_goalSet = new List <Goal>(); this.m_prev = prev; this.m_next = new PropositionLayer(this); foreach (Action act in acts) { this.m_actions.Add(act); CreatePreEdges(act); CreateAddEdges(act); CreateDelEdges(act); } // add no-ops AddNoops(); // 检测互斥的行为 TestMutex(); // 下一层检测互斥的命题 m_next.TestMutex(); }