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); }
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); }
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); }
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); }
static void Main(string[] args) { Console.Write("hello world\n"); /////////////////////// //// Set path variables /////////////////////// Parser.path = @"D:\Documents\Frostbow\VHPOP-PlayTrace\Benchmarks\Rogelio_POCL_compilation"; // Where the Results will be inserted var directory = Parser.path + @"\Results"; System.IO.Directory.CreateDirectory(directory); // Where the ground operator instances will be cached var problemFreezeDirectory = Parser.path + @"\Cached\"; System.IO.Directory.CreateDirectory(problemFreezeDirectory); // Where to read the domain and problem var domainDirectory = Parser.path + @"\domain.pddl"; var problemDirectory = Parser.path + @"\prob01.pddl"; // Where to read the player trace var playerTraceDirectory = Parser.path + @"\chronology_arthur156.pddl"; ///////////////////// //// Read Domain //// ///////////////////// var domain = Parser.GetDomain(domainDirectory, PlanType.PlanSpace); var problem = Parser.GetProblem(problemDirectory); // Create Operators Console.WriteLine("Creating Ground Operators"); GroundActionFactory.Reset(); /* * For compiling the player trace, we only need just those ground instances of steps that appear in the trace * Whereas typically one can follow the following code to Serialize and Deserialize all ground action instances as follows... * * /* * * // To Serialize: it's a large problem, so we only want to read this once. * ProblemFreezer.Serialize(domain, problem, problemFreezeDirectory); * * //// To Deserialize, if we're already read it and serialized * ////ProblemFreezer.Deserialize(problemFreezeDirectory); * * //// If you want to avoid serialization/deserialization, you've got to do this every time. * ////GroundActionFactory.PopulateGroundActions(domain, problem); * /* * * Here instead we read the player trace and compile just those action instances that appear. Note then that this removes the functionality of considering "what-if" actions */ ////////////////////////////////////////////////////// //// Read Player trace /////////////////////////////// ////////////////////////////////////////////////////// // Needs to be set manually because we aren't running standard "Populate" method GroundActionFactory.CreateTypeDict(domain, problem); // playerTraceDirectory var PlanStepList = PlayerTraceUtilities.ReadPlayerTrace(playerTraceDirectory, domain, problem); // Remove those that aren't any good PlanStepList = PlayerTraceUtilities.RemoveUseless(PlanStepList); // Find Quests completed to create goal conditions. var goals = PlayerTraceUtilities.CreateGoalDisjunctions(problem.Initial, PlanStepList); problem.Goal = goals; ///////////////////////////////////////////////////////////////////////////////// // Create Causal Maps (using just those gorund actions found in the plan trace ///////////////////////////////////////////////////////////////////////////////// CacheMaps.Reset(); CacheMaps.CacheLinks(GroundActionFactory.GroundActions); CacheMaps.CacheGoalLinks(GroundActionFactory.GroundActions, problem.Goal); ////////////////////////////////////////////////////// // Create Initial State /////////////////////////// ////////////////////////////////////////////////////// var iniTstate = new State(problem.Initial) as IState; // Use Initial State to Cache effort values VHPOP style CacheMaps.CacheAddReuseHeuristic(iniTstate); ////////////////////////////////////////////////////// // Create Initial Plan/////////////////////////// ////////////////////////////////////////////////////// // Need to modify goal state var initPlan = PlanSpacePlanner.CreateInitialPlan(problem); var lastInsertedStep = initPlan.InitialStep; foreach (var step in PlanStepList) { initPlan.Insert(step); initPlan.Orderings.Insert(lastInsertedStep, step); lastInsertedStep = step; } //////////////////////////////////////////////// //// Run Planner /////////////////////////////// //////////////////////////////////////////////// // Time limit in milliseconds for search var cutoff = 6000000f; // Number of plans to return var k = 1; // Static method called RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 1); /* * ************************************************************ * *************** Other ways to run the planner ************** * ************************************************************ * 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); */ }
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); }