Exemple #1
0
        public static IPlan ReadAndCompile(bool serializeIt, int whichProblem)
        {
            Parser.path = @"D:\documents\frostbow\boltfreezer\";

            GroundActionFactory.Reset();
            CacheMaps.Reset();

            var pfreeze = ReadDomainAndProblem(serializeIt, whichProblem);

            var decomps   = ReadDecompositions();
            var composite = AddCompositeOperator();

            var CompositeMethods = new Dictionary <Composite, List <Decomposition> >();

            CompositeMethods[composite] = decomps;
            Composite.ComposeHTNs(2, CompositeMethods);

            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);

            var initPlan = PlanSpacePlanner.CreateInitialPlan(pfreeze);

            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, initPlan.Goal.Predicates);

            GroundActionFactory.DetectStatics(CacheMaps.CausalTupleMap, CacheMaps.ThreatTupleMap);

            return(initPlan);
        }
Exemple #2
0
        public static void RunProblem(string directory, string domainName, string domainDirectory, Domain domain, Problem problem, float cutoff, int HTN_level, Dictionary <Composite, List <Decomposition> > CompositeMethods)
        {
            // Reset Cached Items
            GroundActionFactory.Reset();
            CacheMaps.Reset();

            var PF = new ProblemFreezer(domainName, domainDirectory, domain, problem);

            PF.Serialize();

            Console.WriteLine("Detecting Statics");
            GroundActionFactory.DetectStatics();

            var initPlan = PlanSpacePlanner.CreateInitialPlan(PF);

            // Removing irrelevant actions
            Console.WriteLine("Removing Irrelevant Actions");
            var staticInitial = initPlan.Initial.Predicates.Where(state => GroundActionFactory.Statics.Contains(state));

            // Every action that has No preconditions which are both static and not in staticInitial
            var possibleActions = GroundActionFactory.GroundActions.Where(action => !action.Preconditions.Any(pre => GroundActionFactory.Statics.Contains(pre) && !staticInitial.Contains(pre)));

            GroundActionFactory.GroundActions = possibleActions.ToList();
            GroundActionFactory.GroundLibrary = possibleActions.ToDictionary(item => item.ID, item => item);

            // Composing HTNs
            Console.WriteLine("Composing HTNs");
            Composite.ComposeHTNs(HTN_level, CompositeMethods);

            // Caching Causal Maps
            Console.WriteLine("Caching Causal Maps");
            CacheMaps.Reset();
            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, initPlan.Goal.Predicates);

            // Cache Heuristic Costs (dynamic programming)
            Console.WriteLine("Caching Heuristic Costs");
            CacheMaps.CacheAddReuseHeuristic(initPlan.Initial);

            // Redo to gaurantee accuracy (needs refactoring)
            initPlan = PlanSpacePlanner.CreateInitialPlan(PF);

            var probNum = Int32.Parse(problem.Name);


            Console.WriteLine(String.Format("Running Problem {0}", probNum));

            RunPlanner(initPlan.Clone() as IPlan, new ADstar(false), new E0(new AddReuseHeuristic(), true), cutoff, directory, probNum);

            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(true), new E0(new AddReuseHeuristic()), cutoff, directory, probNum);
            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(true), new E1(new AddReuseHeuristic()), cutoff, directory, probNum);
            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(true), new E2(new AddReuseHeuristic()), cutoff, directory, probNum);
            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(true), new E3(new AddReuseHeuristic()), cutoff, directory, probNum);
            //RunPlanner(initPlan.Clone() as IPlan, new BFS(false), new Nada(new ZeroHeuristic()), cutoff, directory, probNum);

            // RunPlanner(initPlan.Clone() as IPlan, new BFS(true), new Nada(new ZeroHeuristic()), cutoff, directory, probNum);
        }
Exemple #3
0
        public static IPlan ReadAndCompile(bool serializeIt, int whichProblem)
        {
            Parser.path = @"D:\documents\frostbow\boltfreezer\";

            GroundActionFactory.Reset();
            CacheMaps.Reset();

            // Reads Domain and problem, also populates ground actions and caches causal maps
            var pfreeze = ReadDomainAndProblem(serializeIt, whichProblem);

            // Detecting static conditions
            Console.WriteLine("Detecting Statics");
            GroundActionFactory.DetectStatics();

            var initPlan = PlanSpacePlanner.CreateInitialPlan(pfreeze);

            // Removing irrelevant actions
            Console.WriteLine("Removing Irrelevant Actions");
            var staticInitial = initPlan.Initial.Predicates.Where(state => GroundActionFactory.Statics.Contains(state));

            // Every action that has No preconditions which are both static and not in staticInitial
            var possibleActions = GroundActionFactory.GroundActions.Where(action => !action.Preconditions.Any(pre => GroundActionFactory.Statics.Contains(pre) && !staticInitial.Contains(pre)));

            GroundActionFactory.GroundActions = possibleActions.ToList();
            GroundActionFactory.GroundLibrary = possibleActions.ToDictionary(item => item.ID, item => item);

            var CompositeMethods = ReadCompositeOperators();

            // Composing HTNs
            Console.WriteLine("Composing HTNs");
            Composite.ComposeHTNs(2, CompositeMethods);

            // Caching Causal Maps
            Console.WriteLine("Caching Causal Maps");
            CacheMaps.Reset();
            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, initPlan.Goal.Predicates);
            CacheMaps.CacheAddReuseHeuristic(initPlan.Initial);
            initPlan = PlanSpacePlanner.CreateInitialPlan(pfreeze);


            return(initPlan);
        }
        public static IPlan ReadAndCompile(bool serializeIt, int whichProblem)
        {
            Parser.path = @"D:\documents\frostbow\boltfreezer\";

            GroundActionFactory.Reset();
            CacheMaps.Reset();

            Tuple <Domain, Problem> problemSpec = JustReadDomainAndProblem(whichProblem);
            var domain  = problemSpec.First;
            var problem = problemSpec.Second;

            GroundActionFactory.PopulateGroundActions(domain, problem);
            GroundActionFactory.DetectStatics();
            var subsetOfOps = RemoveIrrelevantActions(new State(problem.Initial));

            GroundActionFactory.Reset();
            GroundActionFactory.GroundActions = subsetOfOps;
            GroundActionFactory.GroundLibrary = subsetOfOps.ToDictionary(item => item.ID, item => item);
            RemoveStaticPreconditions(GroundActionFactory.GroundActions);

            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, problem.Goal);
            CacheMaps.CacheAddReuseHeuristic(new State(problem.Initial));

            var decomps   = ReadDecompositions();
            var composite = AddCompositeOperator();

            var CompositeMethods = new Dictionary <Composite, List <Decomposition> >();

            CompositeMethods[composite] = decomps;
            Composite.ComposeHTNs(2, CompositeMethods);

            // Cache links, now not bothering with statics
            CacheMaps.Reset();
            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, problem.Goal);
            CacheMaps.PrimaryEffectHack(new State(problem.Initial) as IState);


            var initPlan = PlanSpacePlanner.CreateInitialPlan(problem);

            return(initPlan);
        }