public static void AddCompositeStepsToGroundActionFactory(List <IPredicate> Initial, List <IPredicate> Goal, List <CompositeSchedule> compositeSteps) { var originalOps = GroundActionFactory.GroundActions; //CacheMaps.CacheLinks(originalOps); var IOpList = new List <IOperator>(); foreach (var compstep in compositeSteps) { var asIOp = compstep as IOperator; IOpList.Add(asIOp); GroundActionFactory.InsertOperator(asIOp); } // Update Heuristic value for primary effects. PrimaryEffectHack(new State(Initial) as IState); // Amonst themselves CacheMaps.CacheLinks(IOpList); // as consequents to the originals CacheMaps.CacheLinks(originalOps, IOpList); // as antecedants to the originals CacheMaps.CacheLinks(IOpList, originalOps); // as antecedants to goal conditions CacheMaps.CacheGoalLinks(originalOps, Goal); CacheMaps.CacheGoalLinks(IOpList, Goal); }
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(); return(initPlan); }
public void Deserialize() { GroundActionFactory.GroundActions = new List <IOperator>(); GroundActionFactory.GroundLibrary = new Dictionary <int, IOperator>(); foreach (var file in Directory.GetFiles(Parser.GetTopDirectory() + @"Cached\CachedOperators\", testDomainName + "_" + testProblem.Name + "*.CachedOperator")) { var op = BinarySerializer.DeSerializeObject <IOperator>(file); GroundActionFactory.GroundActions.Add(op); GroundActionFactory.GroundLibrary[op.ID] = op; } // THIS is so that initial and goal steps created don't get matched with these Operator.SetCounterExternally(GroundActionFactory.GroundActions.Count + 1); Console.WriteLine("Finding Statics"); GroundActionFactory.DetectStatics(); foreach (var stat in GroundActionFactory.Statics) { Console.WriteLine(stat); } Console.WriteLine("\nCmap\n"); var cmap = BinarySerializer.DeSerializeObject <TupleMap <IPredicate, List <int> > >(CausalMapFileName + ".CachedCausalMap"); CacheMaps.CausalTupleMap = cmap; Console.WriteLine("\nTmap\n"); var tcmap = BinarySerializer.DeSerializeObject <TupleMap <IPredicate, List <int> > >(ThreatMapFileName + ".CachedThreatMap"); CacheMaps.ThreatTupleMap = tcmap; }
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); }
public static List <IPlanStep> ReadPlayerTrace(string directory, Domain domain, Problem problem) { var planTrace = new List <IPlanStep>(); string[] input = System.IO.File.ReadAllLines(directory); foreach (var line in input) { var opToken = PlayerTraceUtilities.CreateOperatorToken(line); var iopToken = PlayerTraceUtilities.AddPreconditionsAndEffects(opToken, domain); // make sure we don't accidentally use.... <_<, >_> opToken = null; var newStep = new PlanStep(); if (GroundActionFactory.GroundActions.Contains(iopToken)) { var opIndex = GroundActionFactory.GroundActions.IndexOf(iopToken); var existingOpToken = GroundActionFactory.GroundActions[opIndex]; newStep = new PlanStep(existingOpToken.Clone() as IOperator); } else { GroundActionFactory.InsertOperator(iopToken); newStep = new PlanStep(iopToken.Clone() as IOperator); } planTrace.Add(newStep); } return(planTrace); }
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 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); } }
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); } }
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 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); }
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 void Deserialize(string directory) { GroundActionFactory.GroundActions = new List <IOperator>(); GroundActionFactory.GroundLibrary = new Dictionary <int, IOperator>(); foreach (var file in Directory.GetFiles(directory + "*.CachedOperator")) { var op = BinarySerializer.DeSerializeObject <IOperator>(file); GroundActionFactory.GroundActions.Add(op); GroundActionFactory.GroundLibrary[op.ID] = op; } // THIS is so that initial and goal steps created don't get matched with these Operator.SetCounterExternally(GroundActionFactory.GroundActions.Count + 1); Console.WriteLine("Finding Statics"); GroundActionFactory.DetectStatics(); foreach (var stat in GroundActionFactory.Statics) { Console.WriteLine(stat); } }
public void AddCompositeStepsToGroundActionFactory(List <CompositeSchedule> compositeSteps) { var goalConditions = InitialPlan.GoalStep.Preconditions; var originalOps = GroundActionFactory.GroundActions; var IOpList = new List <IOperator>(); foreach (var compstep in compositeSteps) { var asIOp = compstep as IOperator; IOpList.Add(asIOp); GroundActionFactory.InsertOperator(asIOp); } // Update Heuristic value for primary effects. PrimaryEffectHack(InitialPlan.Initial); // Amonst themselves CacheMaps.CacheLinks(IOpList); // as antecedants to the originals CacheMaps.CacheLinks(IOpList, originalOps); // as consequents to the originals CacheMaps.CacheLinks(originalOps, IOpList); // as antecedants to goal conditions CacheMaps.CacheGoalLinks(IOpList, goalConditions); // is is possible to have a new precondition here that is static? /// this raises a larger point. /// should we say that initially we observe the way the world is? (yes) /// should we create simple camera shots for conveying actions so that effects of actions are all observable? /// this is an experimental condition of sorts. In this case, there is no non-static condition that is not observable. /// therefore, (no), there is no need for (extra) statics. // There is also no need to cache addreuseheuristic again because primitive values. //CacheMaps.CacheAddReuseHeuristic(InitialPlan.Initial); }
// 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]); }
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); }
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); */ }