Пример #1
0
        public void Serialize()
        {
            Console.WriteLine("Creating Ground Operators");
            GroundActionFactory.PopulateGroundActions(testDomain, testProblem);
            //.Operators, testDomain.ObjectTypes, testProblem.ObjectsByType);
            //BinarySerializer.SerializeObject(FileName, GroundActionFactory.GroundActions);

            // Remove existing cached operators in this domain
            //var di = new DirectoryInfo(Parser.GetTopDirectory() + @"Cached\CachedOperators\");
            //foreach(var file in di.GetFiles())
            //{
            //    var isRightDomain = file.ToString().StartsWith(testDomainName);
            //    if (file.Extension.Equals(".CachedOperator") && isRightDomain)
            //    {
            //        file.Delete();
            //    }
            //}

            foreach (var op in GroundActionFactory.GroundActions)
            {
                BinarySerializer.SerializeObject(FileName + op.GetHashCode().ToString() + ".CachedOperator", op);
            }

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

            BinarySerializer.SerializeObject(CausalMapFileName + ".CachedCausalMap", CacheMaps.CausalTupleMap);
            BinarySerializer.SerializeObject(ThreatMapFileName + ".CachedThreatMap", CacheMaps.ThreatTupleMap);
        }
Пример #2
0
        public static void Serialize(Domain domain, Problem problem, string directory)
        {
            Console.WriteLine("Creating Ground Operators");
            GroundActionFactory.PopulateGroundActions(domain, problem);

            foreach (var op in GroundActionFactory.GroundActions)
            {
                BinarySerializer.SerializeObject(directory + op.GetHashCode().ToString() + ".CachedOperator", op);
            }
        }
Пример #3
0
        public void Serialize()
        {
            Console.Write("Creating Ground Operators");
            GroundActionFactory.PopulateGroundActions(testDomain.Operators, testProblem);

            foreach (var op in GroundActionFactory.GroundActions)
            {
                BinarySerializer.SerializeObject(FileName + op.GetHashCode().ToString() + ".CachedOperator", op);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.Write("hello world\n");

            var cutoff = 100000f;
            var k      = 1;

            // var testDomainName = "batman";
            // var directory = Parser.GetTopDirectory() + @"/Results/" + testDomainName + @"/";
            // System.IO.Directory.CreateDirectory(directory);
            //    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");

            Parser.path = @"D:\Documents\classical-domains\classical\hiking-sat14-strips\";
            var testDomainName = "hiking -sat14-strips";
            var directory      = @"D:\Documents\classical-domains\classical\hiking-sat14-strips\Results\";

            System.IO.Directory.CreateDirectory(directory);
            var testDomainDirectory = @"D:\Documents\classical-domains\classical\hiking-sat14-strips\domain.pddl";
            var testDomain          = Parser.GetDomain(testDomainDirectory, PlanType.PlanSpace);
            var testProblem         = Parser.GetProblem(@"D:\Documents\classical-domains\classical\hiking-sat14-strips\ptesting-1-2-7.pddl");

            Console.WriteLine("Creating Ground Operators");
            GroundActionFactory.Reset();

            GroundActionFactory.PopulateGroundActions(testDomain, testProblem);

            CacheMaps.Reset();
            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, testProblem.Goal);

            var iniTstate = new State(testProblem.Initial) as IState;

            CacheMaps.CacheAddReuseHeuristic(iniTstate);

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

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

            var initPlan = PlanSpacePlanner.CreateInitialPlan(testProblem);

            RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 1);
            //initPlan = PlanSpacePlanner.CreateInitialPlan(testProblem);
            //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);
            //RunPlanner(initPlan.Clone() as IPlan, new BFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 1);
        }
Пример #5
0
        public void Serialize()
        {
            Console.Write("Creating Ground Operators");
            GroundActionFactory.PopulateGroundActions(testDomain.Operators, testProblem);
            //BinarySerializer.SerializeObject(FileName, GroundActionFactory.GroundActions);
            foreach (var op in GroundActionFactory.GroundActions)
            {
                BinarySerializer.SerializeObject(FileName + op.GetHashCode().ToString() + ".CachedOperator", op);
            }

            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, testProblem.Goal);
            BinarySerializer.SerializeObject(CausalMapFileName + ".CachedCausalMap", CacheMaps.CausalMap);
            BinarySerializer.SerializeObject(ThreatMapFileName + ".CachedThreatMap", CacheMaps.ThreatMap);
        }
        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);
        }
Пример #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);
        }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        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");

        string FileName          = Parser.GetTopDirectory() + @"Test\" + testDomainName + "_" + testProblem.Name;
        string CausalMapFileName = Parser.GetTopDirectory() + @"CausalMaps\" + testDomainName + "_" + testProblem.Name;
        string ThreatMapFileName = Parser.GetTopDirectory() + @"CausalMaps\" + testDomainName + "_" + testProblem.Name;

        if (RELOAD)
        {
            Debug.Log("Creating Ground Operators");
            GroundActionFactory.PopulateGroundActions(testDomain.Operators, testProblem);
            //BinarySerializer.SerializeObject(FileName, GroundActionFactory.GroundActions);
            foreach (var op in GroundActionFactory.GroundActions)
            {
                BinarySerializer.SerializeObject(FileName + op.GetHashCode().ToString(), op);
            }

            CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
            CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, testProblem.Goal);
            BinarySerializer.SerializeObject(CausalMapFileName, CacheMaps.CausalMap);
            BinarySerializer.SerializeObject(ThreatMapFileName, CacheMaps.ThreatMap);
        }
        else
        {
            List <IOperator> Operators = new List <IOperator>();
            foreach (string file in Directory.GetFiles(Parser.GetTopDirectory() + @"Cache\" + testDomainName))
            {
                var op = BinarySerializer.DeSerializeObject <IOperator>(file);
                Operators.Add(op);
                //string contents = File.ReadAllText(file);
            }
            //var actions = new List<IOperator>();

            GroundActionFactory.GroundActions = Operators;
        }

        Debug.Log("Caching Maps");


        Debug.Log("Finding static preconditions");

        GroundActionFactory.DetectStatics(CacheMaps.CausalMap, CacheMaps.ThreatMap);


        Debug.Log("Creating initial Plan");
        // Create Initial Plan
        // public Plan(List<IOperator> steps, IState initial, IState goal, Graph<IOperator> og, ICausalLinkGraph clg, Flawque flawQueue)
        // IState _initial, IState _goal, List<IOperator> _steps
        var initialPlan = new Plan(new State(testProblem.Initial) as IState, new State(testProblem.Goal) as IState);

        foreach (var goal in testProblem.Goal)
        {
            initialPlan.Flaws.Insert(initialPlan, new OpenCondition(goal, initialPlan.GoalStep as IOperator));
        }
        Debug.Log("Insert First Ordering");
        initialPlan.Orderings.Insert(initialPlan.InitialStep, initialPlan.GoalStep);

        Debug.Log("First POP");
        var AStarPOP           = new PlanSpacePlanner(initialPlan, SearchType.BestFirst, new AddReuseHeuristic().Heuristic);
        var bestFirstSolutions = AStarPOP.Solve(1, 6000f);

        Debug.Log(bestFirstSolutions[0]);

        var BFSPOP       = new PlanSpacePlanner(initialPlan, SearchType.BFS, new ZeroHeuristic().Heuristic);
        var BFSSolutions = BFSPOP.Solve(1, 6000f);

        Debug.Log(BFSSolutions[0]);

        var DFSPOP       = new PlanSpacePlanner(initialPlan, SearchType.DFS, new ZeroHeuristic().Heuristic);
        var DFSSolutions = DFSPOP.Solve(1, 6000f);

        Debug.Log(DFSSolutions[0]);
    }