private bool Contains(CompoundFormula cf) { HashSet<Predicate> lPredicates = cf.GetAllPredicates(); Predicate pCanonical = null; foreach (Predicate p in lPredicates) { pCanonical = p.Canonical(); if (!m_dMapPredicatesToFormulas.ContainsKey((GroundedPredicate)pCanonical)) return false; } List<int> lFormulas = m_dMapPredicatesToFormulas[(GroundedPredicate)pCanonical]; foreach (int idx in lFormulas) if (m_lHiddenFormulas[idx] != null && m_lHiddenFormulas[idx].Equals(cf)) return true; return false; }
private List<Action> CreateReasoningActions(CompoundFormula cf) { List<Action> lActions = new List<Action>(); Action a = null; HashSet<Predicate> lPredicates = new HashSet<Predicate>(); cf.GetAllPredicates(lPredicates); foreach (Predicate p in lPredicates) { a = CreateReasoningAction(p, lPredicates); if( a != null ) lActions.Add(a); } return lActions; }
public void AddInitialStateFormula(CompoundFormula cf) { if (false && !cf.IsSimpleFormula()) { CompoundFormula cfCNF = (CompoundFormula)cf.ToCNF(); foreach (CompoundFormula cfSub in cfCNF.Operands) AddInitialStateFormula(cfSub); return; } m_lOriginalHiddenFormulas.Add(cf); m_lHiddenFormulas.Add((CompoundFormula)cf); EfficientFormula ef = new EfficientFormula(cf.Operator); ef.OriginalFormula = cf; m_lEfficientHidden.Add(ef); HashSet<Predicate> lHidden = cf.GetAllPredicates(); foreach (Predicate p in lHidden) { GroundedPredicate pCanonical = (GroundedPredicate)p.Canonical(); if (!Unknown.Contains(pCanonical)) Unknown.Add(pCanonical); if (!m_dMapPredicatesToFormulas.ContainsKey(pCanonical)) { m_dMapPredicatesToFormulas[pCanonical] = new List<int>(); int iIndex = m_dMapIndexToPredicate.Count; m_dMapIndexToPredicate.Add(pCanonical); m_dMapPredicatesToIndexes[pCanonical] = iIndex; m_dMapPredicateToEfficientFormula.Add(new List<int>()); } int iPredicate = m_dMapPredicatesToIndexes[pCanonical]; ef.SetVariableValue(iPredicate, !p.Negation); m_dMapPredicateToEfficientFormula[iPredicate].Add(m_lEfficientHidden.Count - 1); m_dMapPredicatesToFormulas[pCanonical].Add(m_lHiddenFormulas.Count - 1); } m_cfCNFHiddenState.AddOperand(cf); if (!cf.IsSimpleConjunction() && !cf.IsSimpleOneOf() && SDRPlanner.EnforceCNF) { m_cfCNFHiddenState = (CompoundFormula)m_cfCNFHiddenState.ToCNF(); } }