/// <summary> /// foamliu, 2009/01/20. /// /// 目标可达且彼此不互斥. /// </summary> /// <returns></returns> private bool GoalsReachable() { // 首先是所有目标中的命题都在. foreach (string literal in this.m_goal.Literals) { if (!this.m_lastProp.Conjunction.Literals.Contains(literal)) { return(false); } } // 其次目标中的命题不彼此互斥. for (int i = 0; i < m_goal.Literals.Count; i++) { Proposition theProp1 = m_lastProp.GetProposition(m_goal.Literals[i]); for (int j = i + 1; j < m_goal.Literals.Count; j++) { Proposition theProp2 = m_lastProp.GetProposition(m_goal.Literals[j]); if (theProp1.IsMutex(theProp2)) { return(false); } } } return(true); }
/// <summary> /// foamliu, 2009/01/22. /// /// 是否选中的 action 已经可以满足它. /// </summary> /// <returns></returns> private bool SatisfiedBySelectedActions(Proposition theProp) { foreach (Action theAct in m_selectedActions) { if (theProp.AddEdges.Contains(theAct)) { return(true); } } return(false); }
/// <summary> /// foamliu, 2009/01/21, 建立 Del-Effects 边. /// </summary> private void CreateDelEdges(Action theAct) { Conjunction add = theAct.DelEffects; foreach (string s in add.Literals) { Proposition theProp = m_next.AddProposition(s); theProp.AddDelEdge(theAct); theAct.AddDelProp(theProp); } }
/// <summary> /// foamliu, 2009/01/21, 建立 PreCondition 边. /// /// 例如: /// Move ( b1, b2, b3 ) /// PreCondition 是: /// ON (b1, b2) & Clear (b1) & Clear (b3) /// </summary> /// <param name="theAct"></param> private void CreatePreEdges(Action theAct) { Conjunction pre = theAct.PreCondition; foreach (string s in pre.Literals) { Proposition theProp = m_prev.GetProposition(s); theProp.AddPreEdge(theAct); theAct.AddPreProp(theProp); } }
public Proposition AddProposition(Proposition thePro) { // foamliu, 2009/01/22, fix a bug: // {"An item with the same key has already been added."}. if (m_dict.ContainsKey(thePro.Name)) { return(m_dict[thePro.Name]); } m_props.Add(thePro); m_dict.Add(thePro.Name, thePro); m_conj.Literals.Add(thePro.Name); return(thePro); }
/// <summary> /// foamliu, 2009/01/22, 检测命题互斥. /// /// 要求所有相关的 action 都彼此互斥. /// </summary> /// <param name="theProp1"></param> /// <param name="theProp2"></param> /// <returns></returns> private bool TestActions(Proposition theProp1, Proposition theProp2) { foreach (Action theAct1 in theProp1.AddEdges) { foreach (Action theAct2 in theProp2.AddEdges) { if (theAct1.IsMutex(theAct2) == false) { return(false); } } } return(true); }
/// <summary> /// foamliu, 2009/01/22, 检测互斥的命题. /// /// 下面这段拷贝自如下论文的 2.2 节: /// "Fast Planning Through Planning Graph Analysis" /// Two propositions p and q in a proposition-level are marked as exclusive if all ways of /// creating proposition p are exclusive of all ways of creating proposition q. Specifically, they /// are marked as exclusive if each action a having an add-edge to proposition p is marked as /// exclusive of each action b having an add-edge to proposition q. /// </summary> public void TestMutex() { for (int i = 0; i < m_props.Count; i++) { for (int j = i + 1; j < m_props.Count; j++) { Proposition theProp1 = m_props[i]; Proposition theProp2 = m_props[j]; if (TestActions(theProp1, theProp2)) { theProp1.MutexProps.Add(theProp2); theProp2.MutexProps.Add(theProp1); } } } }
/// <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); } }
public bool IsMutex(Proposition otherProp) { return(m_mutexProps.Contains(otherProp)); }
public void AddDelProp(Proposition prop) { this.m_delProps.Add(prop); }
public void AddAddProp(Proposition prop) { this.m_addProps.Add(prop); }
public void AddPreProp(Proposition prop) { this.m_preEdges.Add(prop); }