/// <summary> /// foamliu, 2009/01/22, 得到规划. /// /// </summary> /// <returns></returns> public List <string> GetPlan() { List <string> plan = new List <string>(); ActionLayer aLayer = this.m_firstProp.NextLayer; while (aLayer != null) { plan.AddRange(aLayer.GetSelectedActions()); aLayer = aLayer.NextLayer.NextLayer; } List <string> temp = new List <string>(); temp.AddRange(plan); plan.Clear(); foreach (string step in temp) { if (step.StartsWith("NOOP") == false && plan.Contains(step) == false) { plan.Add(step); } } return(plan); }
public PropositionLayer(ActionLayer prev) { this.m_prev = prev; this.m_props = new List <Proposition>(); this.m_dict = new Dictionary <string, Proposition>(); this.m_conj = new Conjunction(); }
/// <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. /// /// 从后往前一层层的搜索, 比如假设 Pj 层包含目标中的所有命题, 首先在 Aj-1 层找到以这些目标命题为正效果的行为, /// 然后在 Pj-1 找这些行为的前提. /// </summary> public bool SearchPlan(Conjunction theGoals) { GenGoalSet(theGoals); if (SearchTheLayer(0)) { Conjunction newGoals = new Conjunction(); foreach (Action theAct in m_selectedActions) { newGoals.AddConjunction(theAct.PreCondition); } ActionLayer aLayer = m_prev.PrevLayer; if (aLayer == null) // no more layers we reached the init state { return(true); } return(aLayer.SearchPlan(newGoals)); } else { return(false); } }
/// <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); }