public void PrepareAndRun()
        {
            Parser.path = @"D:\documents\frostbow\";
            UPC.ReadProblem();

            if (DeCacheIt)
            {
                DeCacheIt = false;
                cacheManager.DeCacheIt();
            }
            else if (justCacheMapsAndEffort)
            {
                cacheManager.DecacheSteps();
                AddObservedNegativeConditions(UPC);

                CacheMaps.CacheLinks(GroundActionFactory.GroundActions);
                CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, UPC.goalPredicateList);
                CacheMaps.CacheAddReuseHeuristic(new State(UPC.initialPredicateList) as IState);
                UnityGroundActionFactory.PrimaryEffectHack(new State(UPC.initialPredicateList) as IState);

                cacheManager.justCacheMapsAndEffort = true;
                cacheManager.CacheIt();
                cacheManager.justCacheMapsAndEffort = false;
                return;
            }
            else
            {
                UGAF.PreparePlanner(true);
                GroundActionFactory.GroundActions = new HashSet <IOperator>(GroundActionFactory.GroundActions).ToList();
                AddObservedNegativeConditions(UPC);
                UnityGroundActionFactory.CreateSteps(UPC, UGAF.DecompositionSchemata);

                cacheManager.CacheIt();
            }

            var initialPlan = PlannerScheduler.CreateInitialPlan(UPC.initialPredicateList, UPC.goalPredicateList);


            Debug.Log("Planner and initial plan Prepared");

            // MW-Loc-Conf
            var solution = Run(initialPlan, new ADstar(false), new E0(new AddReuseHeuristic(), true), cutoffTime);

            //var solution = Run(initialPlan, new ADstar(false), new E3(new AddReuseHeuristic()), cutoffTime);
            //var solution = Run(initPlan, new BFS(), new Nada(new ZeroHeuristic()), 20000);
            if (solution != null)
            {
                //Debug.Log(solution.ToStringOrdered());
                PlanSteps = new List <string>();
                foreach (var step in solution.Orderings.TopoSort(solution.InitialStep))
                {
                    Debug.Log(step);
                    PlanSteps.Add(step.ToString());
                }
            }
            else
            {
                Debug.Log("No good");
            }
        }
예제 #2
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);
            }
        }
        public IPlan Run(IPlan initPlan, ISearch SearchMethod, ISelection SelectMethod, float cutoff)
        {
            var directory = Parser.GetTopDirectory() + "/Results/";

            System.IO.Directory.CreateDirectory(directory);
            var POP = new PlannerScheduler(initPlan.Clone() as IPlan, SelectMethod, SearchMethod)
            {
                directory     = directory,
                problemNumber = 0
            };

            Debug.Log("Running plan-search");
            var Solutions = POP.Solve(1, cutoff);

            if (Solutions != null)
            {
                return(Solutions[0]);
            }
            Debug.Log(string.Format("explored: {0}, expanded: {1}", POP.Open, POP.Expanded));
            return(null);
        }
예제 #4
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);
        }