Example #1
0
        private HashSet <Predicate> ReachablePredicates(HashSet <Predicate> lInitial, List <Action> lFiltered)
        {
            HashSet <Predicate> lReachable = new HashSet <Predicate>(lInitial);
            List <Action>       lUnapplied = new List <Action>(lFiltered);
            bool bChanged = true;

            while (bChanged)
            {
                bChanged = false;
                List <Action> lNewUnapplied = new List <Action>();
                foreach (Action a in lUnapplied)
                {
                    //if (a.Name.Contains("p3-1") && a.Name.Contains("smell"))
                    //    Console.WriteLine("*");
                    if (a.Preconditions.IsTrue(lReachable, true))
                    {
                        Formula             f        = a.GetApplicableEffects(lReachable, true);
                        HashSet <Predicate> lEffects = f.GetAllPredicates();
                        foreach (Predicate p in lEffects)
                        {
                            if (lReachable.Add(p))
                            {
                                bChanged = true;
                            }
                        }
                    }
                    else
                    {
                        lNewUnapplied.Add(a);
                    }
                }
                lUnapplied = lNewUnapplied;
            }
            return(lReachable);
        }
Example #2
0
        private CompoundFormula AddKnowledgePredicatesToFormula(Formula f, HashSet <Predicate> lKnowPredicates)
        {
            CompoundFormula     cf          = new CompoundFormula("and");
            HashSet <Predicate> lPredicates = new HashSet <Predicate>();

            f.GetAllPredicates(lPredicates);
            foreach (Predicate p in lPredicates)
            {
                if (lKnowPredicates.Contains(p))
                {
                    KnowPredicate kp = new KnowPredicate(p);
                    cf.AddOperand(new PredicateFormula(kp));
                }
            }
            if (f is CompoundFormula && ((CompoundFormula)f).Operator == "and")
            {
                foreach (Formula fSub in ((CompoundFormula)f).Operands)
                {
                    cf.AddOperand(fSub);
                }
            }
            else
            {
                cf.AddOperand(f);
            }
            return(cf);
        }
Example #3
0
        private void FilterActions(List <Action> lGrounded, Formula fCurrent, List <Action> lFiltered, List <Action> lLandmarkAchievers)
        {
            HashSet <Predicate> lLandmark = fCurrent.GetAllPredicates();

            foreach (Action a in lGrounded)
            {
                HashSet <Predicate> lConditionalEffects = new HashSet <Predicate>(), lNonConditionalEffects = new HashSet <Predicate>();
                a.Effects.GetAllEffectPredicates(lConditionalEffects, lNonConditionalEffects);
                bool bAchieveLandmark = false;
                foreach (Predicate p in lLandmark)
                {
                    if (lConditionalEffects.Contains(p) || lNonConditionalEffects.Contains(p))
                    {
                        bAchieveLandmark = true;
                        break;
                    }
                }
                if (bAchieveLandmark)
                {
                    lLandmarkAchievers.Add(a);
                }
                else
                {
                    lFiltered.Add(a);
                }
            }
        }
 public RegressionHeuristic(Domain d, Formula fGoal, bool bMax)
 {
     m_dDomain = d;
     m_bMax = bMax;
     m_lGoal = new List<Predicate>(fGoal.GetAllPredicates());
     //ComputeFullRegression();
 }
 public RegressionHeuristic(Domain d, Formula fGoal, bool bMax)
 {
     m_dDomain = d;
     m_bMax    = bMax;
     m_lGoal   = new List <Predicate>(fGoal.GetAllPredicates());
     //ComputeFullRegression();
 }
 public HSPHeuristic(Domain d, Formula fGoal, bool bMax)
 {
     m_dDomain = d;
     m_bMax    = bMax;
     m_lGoal   = new List <Predicate>(fGoal.GetAllPredicates());
     //foreach (PredicateFormula vf in ((CompoundFormula)fGoal).Operands)
     //    m_lGoal.Add(vf.Predicate);
     //ComputeAllEffectsPreconditions();
 }
 public HSPHeuristic(Domain d, Formula fGoal, bool bMax)
 {
     m_dDomain = d;
     m_bMax = bMax;
     m_lGoal = new List<Predicate>(fGoal.GetAllPredicates());
     //foreach (PredicateFormula vf in ((CompoundFormula)fGoal).Operands)
     //    m_lGoal.Add(vf.Predicate);
     //ComputeAllEffectsPreconditions();
 }
Example #8
0
        private void FilterActions(List <Action> lGrounded, Formula fCurrent, List <Action> lFiltered, List <Action> lLandmarkAchievers,
                                   Dictionary <Predicate, List <Action> > dPreconditionToAction, Dictionary <Predicate, List <Action> > dEffectToAction,
                                   HashSet <Predicate> lInitialState)
        {
            HashSet <Predicate> lLandmark     = fCurrent.GetAllPredicates();
            HashSet <string>    hsPreNames    = new HashSet <string>();
            HashSet <string>    hsEffectNames = new HashSet <string>();

            foreach (Predicate p in lLandmark)
            {
                if (!lInitialState.Contains(p))
                {
                    if (dPreconditionToAction.ContainsKey(p))
                    {
                        foreach (Action a in dPreconditionToAction[p])
                        {
                            hsPreNames.Add(a.Name);
                        }
                    }
                }
                if (dEffectToAction.ContainsKey(p))
                {
                    foreach (Action a in dEffectToAction[p])
                    {
                        hsEffectNames.Add(a.Name);
                    }
                }
            }

            foreach (Action a in lGrounded)
            {
                //if (a.Name.Contains("p3-1") && a.Name.Contains("smell"))
                //   Console.WriteLine("*");

                if (hsEffectNames.Contains(a.Name))
                {
                    lLandmarkAchievers.Add(a);
                }
                else if (!hsPreNames.Contains(a.Name))
                {
                    lFiltered.Add(a);
                }
            }
        }
Example #9
0
        private Dictionary <Predicate, List <Action> > GetLandmarkAchievers(Formula fLandmark, HashSet <Predicate> lAllReachable, List <Action> lPotentialLandmarkAchievers)
        {
            Dictionary <Predicate, List <Action> > dActions = new Dictionary <Predicate, List <Action> >();
            HashSet <Predicate> lLandmark = fLandmark.GetAllPredicates();

            foreach (Predicate p in lLandmark)
            {
                dActions[p] = new List <Action>();
                foreach (Action a in lPotentialLandmarkAchievers)
                {
                    if (a.Preconditions.IsTrue(lAllReachable))
                    {
                        Formula             fEffects = a.GetApplicableEffects(lAllReachable, false);
                        HashSet <Predicate> lEffects = fEffects.GetAllPredicates();
                        if (lEffects.Contains(p))
                        {
                            dActions[p].Add(a);
                        }
                    }
                }
            }
            return(dActions);
        }
        private Dictionary<Predicate, List<Action>> GetLandmarkAchievers(Formula fLandmark, HashSet<Predicate> lAllReachable, List<Action> lPotentialLandmarkAchievers)
        {
            Dictionary<Predicate, List<Action>> dActions = new Dictionary<Predicate, List<Action>>();
            HashSet<Predicate> lLandmark = fLandmark.GetAllPredicates();
            foreach (Predicate p in lLandmark)
            {
                dActions[p] = new List<Action>();
                foreach (Action a in lPotentialLandmarkAchievers)
                {
                    if (a.Preconditions.IsTrue(lAllReachable))
                    {
                        Formula fEffects = a.GetApplicableEffects(lAllReachable, false);
                        HashSet<Predicate> lEffects = fEffects.GetAllPredicates();
                        if (lEffects.Contains(p))
                        {
                            dActions[p].Add(a);
                        }
                    }
                }

            }
            return dActions;
        }
        private void FilterActions(List<Action> lGrounded, Formula fCurrent, List<Action> lFiltered, List<Action> lLandmarkAchievers, 
            Dictionary<Predicate, List<Action>> dPreconditionToAction, Dictionary<Predicate, List<Action>> dEffectToAction, 
            HashSet<Predicate> lInitialState)
        {
            HashSet<Predicate> lLandmark = fCurrent.GetAllPredicates();
            HashSet<string> hsPreNames = new HashSet<string>();
            HashSet<string> hsEffectNames = new HashSet<string>();
            foreach (Predicate p in lLandmark)
            {
                if (!lInitialState.Contains(p))
                {
                    if (dPreconditionToAction.ContainsKey(p))
                    {
                        foreach (Action a in dPreconditionToAction[p])
                            hsPreNames.Add(a.Name);
                    }
                }
                if (dEffectToAction.ContainsKey(p))
                {
                    foreach (Action a in dEffectToAction[p])
                        hsEffectNames.Add(a.Name);
                }
            }

            foreach (Action a in lGrounded)
            {
                //if (a.Name.Contains("p3-1") && a.Name.Contains("smell"))
                 //   Console.WriteLine("*");

                if (hsEffectNames.Contains(a.Name))
                    lLandmarkAchievers.Add(a);
                else if(!hsPreNames.Contains(a.Name))
                    lFiltered.Add(a);
            }
        }
 private void FilterActions(List<Action> lGrounded, Formula fCurrent, List<Action> lFiltered, List<Action> lLandmarkAchievers)
 {
     HashSet<Predicate> lLandmark = fCurrent.GetAllPredicates();
     foreach (Action a in lGrounded)
     {
         HashSet<Predicate> lConditionalEffects = new HashSet<Predicate>(), lNonConditionalEffects = new HashSet<Predicate>();
         a.Effects.GetAllEffectPredicates(lConditionalEffects, lNonConditionalEffects);
         bool bAchieveLandmark = false;
         foreach (Predicate p in lLandmark)
         {
             if (lConditionalEffects.Contains(p) || lNonConditionalEffects.Contains(p))
             {
                 bAchieveLandmark = true;
                 break;
             }
         }
         if (bAchieveLandmark)
             lLandmarkAchievers.Add(a);
         else
             lFiltered.Add(a);
     }
 }
 private CompoundFormula AddKnowledgePredicatesToFormula(Formula f, HashSet<Predicate> lKnowPredicates)
 {
     CompoundFormula cf = new CompoundFormula("and");
     HashSet<Predicate> lPredicates = new HashSet<Predicate>();
     f.GetAllPredicates(lPredicates);
     foreach (Predicate p in lPredicates)
     {
         if (lKnowPredicates.Contains(p))
         {
             KnowPredicate kp = new KnowPredicate(p);
             cf.AddOperand(new PredicateFormula(kp));
         }
     }
     if (f is CompoundFormula && ((CompoundFormula)f).Operator == "and")
     {
         foreach (Formula fSub in ((CompoundFormula)f).Operands)
             cf.AddOperand(fSub);
     }
     else
         cf.AddOperand(f);
     return cf;
 }