コード例 #1
0
        public void IdentifyLandmarks(Problem p, Domain d)
        {
            //State s0 = p.GetInitialBelief().ChooseState(true);
            Console.WriteLine("Started identifying landmarks");
            HashSet <Predicate> lInitialState = new HashSet <Predicate>(p.Known);

            lInitialState = CompleteNegations(lInitialState, d);
            List <Formula>  lLandmarks     = new List <Formula>();
            Queue <Formula> qOpenLandmarks = new Queue <Formula>();

            Console.WriteLine("Grounding actions");
            List <Action> lGrounded = d.GroundAllActions(p);

            Console.WriteLine("Removing disjunctions, conditional effects, and filtering impossible actions");
            List <Action> lNoDisjunctions = RemoveDisjunctions(lGrounded);//remove disjunctions before grounding?
            List <Action> lSimple         = RemoveConditions(lNoDisjunctions);

            lSimple = FilterImpossible(lSimple, lInitialState, d);
            //lSimple = RemoveNegativePreconditions(lSimple);//need to remove this! enables many illegal actions - must work with complete positive and negative specification
            Dictionary <Predicate, List <Action> > dPreconditionToAction = new Dictionary <Predicate, List <Action> >();
            Dictionary <Predicate, List <Action> > dEffectToAction       = new Dictionary <Predicate, List <Action> >();

            ClassifyActions(lSimple, dPreconditionToAction, dEffectToAction);
            Console.WriteLine("Processing landmarks");
            foreach (Predicate pLandmark in p.Goal.GetAllPredicates())
            {
                lLandmarks.Add(new PredicateFormula(pLandmark));
                qOpenLandmarks.Enqueue(new PredicateFormula(pLandmark));
            }
            Dictionary <Predicate, List <Formula> > dLandmarksForPredicate = new Dictionary <Predicate, List <Formula> >();
            int cProcessed = 0;

            while (qOpenLandmarks.Count > 0)
            {
                Formula       fCurrent = qOpenLandmarks.Dequeue();
                List <Action> lFiltered = new List <Action>(), lPotentialLandmarkAchievers = new List <Action>();
                FilterActions(lSimple, fCurrent, lFiltered, lPotentialLandmarkAchievers, dPreconditionToAction, dEffectToAction, lInitialState);
                HashSet <Predicate> lAllReachable = ReachablePredicates(lInitialState, lFiltered);
                Dictionary <Predicate, List <Action> > dLandmarkAchievers = GetLandmarkAchievers(fCurrent, lAllReachable, lPotentialLandmarkAchievers);
                List <Formula> lNewLandmarks = RegressLandmark(fCurrent, dLandmarkAchievers, lInitialState);
                foreach (Formula fNew in lNewLandmarks)
                {
                    bool bAlreadyFound = false;
                    foreach (Predicate pLandmark in fNew.GetAllPredicates())
                    {
                        if (!dLandmarksForPredicate.ContainsKey(pLandmark))
                        {
                            dLandmarksForPredicate[pLandmark] = new List <Formula>();
                        }
                        else
                        {
                            foreach (Formula fExisting in dLandmarksForPredicate[pLandmark])
                            {
                                if (fExisting.Size <= fNew.Size)
                                {
                                    bAlreadyFound = true;
                                }
                            }
                        }
                        dLandmarksForPredicate[pLandmark].Add(fNew);
                    }
                    if (!bAlreadyFound)
                    {
                        qOpenLandmarks.Enqueue(fNew);
                        lLandmarks.Add(fNew);
                    }
                }
                cProcessed++;
                if (cProcessed % 10 == 0)
                {
                    Console.WriteLine("Processed " + cProcessed + " found " + lLandmarks.Count + " in queue " + qOpenLandmarks.Count);
                }
            }
            StreamWriter sw = new StreamWriter("D:\\" + d.Name + ".Landmarks.txt");

            foreach (Formula f in lLandmarks)
            {
                sw.WriteLine(f);
            }
            sw.Close();
        }
コード例 #2
0
 public ForwardSearchPlanner(Domain d, Problem p, HeuristicFunction fHeuristic)
     : base(d, p)
 {
     m_fHeuristic = fHeuristic;
 }