Exemple #1
0
        static void Main(string[] args)
        {
            Console.Write("hello world\n");
            Parser.path = @"D:\documents\frostbow\VHSP-Csharp-Frostbow\";
            var directory = Parser.GetTopDirectory() + @"/Results/";
            var cutoff    = 6000f;
            var k         = 1;

            var testDomainName      = "batman";
            var testDomainDirectory = Parser.GetTopDirectory() + @"Benchmarks\" + testDomainName + @"\domain.pddl";
            var testDomain          = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + testDomainName + @"\domain.pddl", PlanType.PlanSpace);
            var testProblem         = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + testDomainName + @"\prob01.pddl");

            var problemFreezer = new ProblemFreezer(testDomainName, testDomainDirectory, testDomain, testProblem);

            // problemFreezer.Serialize();
            problemFreezer.Deserialize();

            var initPlan = StateSpacePlanner.CreateInitialPlan(problemFreezer);

            RunPlanner(initPlan.Clone() as IPlan, new BFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 1);

            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 1);
            //RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new NumOpenConditionsHeuristic()), k, cutoff, directory, 1);
            //RunPlanner(initPlan.Clone() as IPlan, new DFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 1);
            //
        }
Exemple #2
0
        public static void TestBenchmarks()
        {
            var domainNames = new List <string>()
            {
                "arth", "batman"
            };

            foreach (var dn in domainNames)
            {
                var testDomainDirectory = Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\domain.pddl";
                var testDomain          = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\domain.pddl", PlanType.PlanSpace);
                var testProblem         = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\prob01.pddl");

                ProblemFreezer PF = new ProblemFreezer(dn, testDomainDirectory, testDomain, testProblem);
                PF.Serialize();

                var directory = @"D:\Documents\Frostbow\Benchmarks\Results\";
                var cutoff    = 6000f;
                var k         = 1;

                var initPlan = PlanSpacePlanner.CreateInitialPlan(PF);

                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E1(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E2(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E3(new AddReuseHeuristic()), k, cutoff, directory, 0);
                //RunPlanner(initPlan.Clone() as IPlan, new DFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new BFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 0);
            }
        }
Exemple #3
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);
        }
        public static IPlan CreateInitialPlan(ProblemFreezer PF)
        {
            var initialPlan = new Plan(new State(PF.testProblem.Initial) as IState, new State(PF.testProblem.Goal) as IState);

            foreach (var goal in PF.testProblem.Goal)
            {
                initialPlan.Flaws.Add(initialPlan, new OpenCondition(goal, initialPlan.GoalStep as IPlanStep));
            }
            initialPlan.Orderings.Insert(initialPlan.InitialStep, initialPlan.GoalStep);
            return(initialPlan);
        }
Exemple #5
0
        // Update is called once per frame
        void Update()
        {
            if (compilePrimitiveSteps)
            {
                compilePrimitiveSteps = false;
                initialPlan           = PreparePlanner(true);
                PrimitiveOps          = GroundActionFactory.GroundActions;
                PrimitiveSteps        = PrimitiveOps.Count;
                CompositeSteps        = 0;
            }

            if (compileCompositeSteps)
            {
                compileCompositeSteps = false;
                CompileCompositeSteps();
            }

            if (checkEffects)
            {
                checkEffects = false;
                foreach (var compstep in CompositeOps)
                {
                    foreach (var effect in compstep.Effects)
                    {
                        if (effect.Name != "obs") // && effect.Name != "obs-starts")
                        {
                            continue;
                        }
                        Debug.Log(effect.ToString());
                    }
                }
                // do we have what we need?
            }

            if (regenerateInitialPlanWithComposite)
            {
                regenerateInitialPlanWithComposite = false;

                Parser.path = "/";
                var domainOperatorComponent = GameObject.FindGameObjectWithTag("ActionHost").GetComponent <DomainOperators>();
                domainOperatorComponent.Reset();
                var problem  = CreateProblem(domainOperatorComponent.DomainOps);
                var domain   = CreateDomain(domainOperatorComponent);
                var PF       = new ProblemFreezer("Unity", "", domain, problem);
                var initPlan = PlannerScheduler.CreateInitialPlan(PF);
                CacheMaps.CacheAddReuseHeuristic(initPlan.Initial);
                PrimaryEffectHack(InitialPlan.Initial);
            }
        }
Exemple #6
0
        public static ProblemFreezer ReadDomainAndProblem(bool serializeIt, int whichProblem)
        {
            var domainName      = "blocks";
            var domainDirectory = Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl";
            var domain          = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl", PlanType.PlanSpace);
            var problem         = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob0" + whichProblem.ToString() + @".pddl");

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

            if (serializeIt)
            {
                PF.Serialize();
            }
            else
            {
                PF.Deserialize();
            }
            return(PF);
        }
Exemple #7
0
        public IPlan PreparePlanner(bool resetCache)
        {
            Parser.path = "/";

            // Update Domain Operators
            var domainOperatorComponent = GameObject.FindGameObjectWithTag("ActionHost").GetComponent <DomainOperators>();

            domainOperatorComponent.Reset();

            // Read and Create Problem
            var problem = CreateProblem(domainOperatorComponent.DomainOps);

            // Create Domain
            var domain = CreateDomain(domainOperatorComponent);

            // Create Problem Freezer.
            var PF = new ProblemFreezer("Unity", "", domain, problem);

            // Create Initial Plan
            var initPlan = PlannerScheduler.CreateInitialPlan(PF);

            if (!resetCache)
            {
                if (GroundActionFactory.GroundActions != null)
                {
                    if (HeuristicMethods.visitedPreds == null || HeuristicMethods.visitedPreds.Get(true).Count == 0)
                    {
                        CacheMaps.CacheAddReuseHeuristic(initPlan.Initial);
                        //PrimaryEffectHack(initPlan.Initial);
                    }
                    Debug.Log("test");
                    return(initPlan);
                }
            }

            // Reset Cache
            GroundActionFactory.Reset();
            CacheMaps.Reset();

            GroundActionFactory.PopulateGroundActions(domain, problem);

            // Remove Irrelevant Actions (those which require an adjacent edge but which does not exist. In Refactoring--> make any static
            Debug.Log("removing irrelevant actions");
            var adjInitial      = initPlan.Initial.Predicates.Where(state => state.Name.Equals("adjacent"));
            var replacedActions = new List <IOperator>();

            foreach (var ga in GroundActionFactory.GroundActions)
            {
                // If this action has a precondition with name adjacent this is not in initial state, then it's impossible. True ==> impossible. False ==> OK!
                var isImpossible = ga.Preconditions.Where(pre => pre.Name.Equals("adjacent") && pre.Sign).Any(pre => !adjInitial.Contains(pre));
                if (isImpossible)
                {
                    continue;
                }
                replacedActions.Add(ga);
            }
            GroundActionFactory.Reset();
            GroundActionFactory.GroundActions = replacedActions;
            GroundActionFactory.GroundLibrary = replacedActions.ToDictionary(item => item.ID, item => item);


            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, problem.Goal);


            // Detect Statics
            Debug.Log("Detecting Statics");
            GroundActionFactory.DetectStatics(CacheMaps.CausalTupleMap, CacheMaps.ThreatTupleMap);


            Debug.Log("Caching Heuristic costs");
            CacheMaps.CacheAddReuseHeuristic(initPlan.Initial);

            // Recreate Initial Plan
            initPlan = PlannerScheduler.CreateInitialPlan(PF);

            return(initPlan);
        }
Exemple #8
0
 public new static IPlan CreateInitialPlan(ProblemFreezer PF)
 {
     return(CreateInitialPlan(PF.testProblem));
 }
 public static IPlan CreateInitialPlan(ProblemFreezer PF)
 {
     return(new Plan(new State(PF.testProblem.Initial) as IState, new State(PF.testProblem.Goal) as IState) as IPlan);
 }