public Trie <int> createDB(string problemFile, DomainDependentSolver domainSpecificSolver, long numberOfSamples, TimeSpan maxTime, bool storeDB = true) { System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); DB = new Trie <int>(); int samples = 0; enumerator.problem = new Problem(problemFile, false); var states = enumerator.enumerateStates(); var problem = new Problem(problemFile, false); foreach (var state in states) { samples++; if (samples > numberOfSamples || watch.Elapsed > maxTime) { break; } problem.SetInitialState(state); domainSpecificSolver.SetProblem(problem); int goalDistance = (int)Math.Floor(domainSpecificSolver.Search(quiet: true)); var stateString = state.ToString(); DB.add(stateString.Substring(0, stateString.Length - 2), goalDistance); //skipes two last two characters of the string. They are always the same. } if (storeDB) { DB.store(getDBFilePath(problemFile)); } return(DB); }
public IEnumerable <(string key, int val)> createSamples(string problemFile, DomainDependentSolver domainSpecificSolver, long numberOfSamples, TimeSpan maxTime, bool storeDB = true) { System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); int samples = 0; enumerator.problem = new Problem(problemFile, false); var states = enumerator.enumerateStates(); var problem = new Problem(problemFile, false); HashSet <string> alreadyGenerated = new HashSet <string>(); int hashSetHits = 0; foreach (var state in states) { if (samples > numberOfSamples || watch.Elapsed > maxTime || hashSetHits > alreadyGenerated.Count) { break; } string stateString = state.ToString(); if (alreadyGenerated.Contains(stateString)) { hashSetHits++; continue; } alreadyGenerated.Add(stateString); samples++; problem.SetInitialState(state); domainSpecificSolver.SetProblem(problem); int goalDistance = (int)Math.Floor(domainSpecificSolver.Search(quiet: true)); yield return(stateString.Substring(0, stateString.Length - 2), goalDistance); //skipes two last two characters of the string. They are always the same. } }
protected override double GetValueImpl(PAD.Planner.IState state) { var problem = solver.sasProblem; problem.SetInitialState(state); solver.SetProblem(problem); return(solver.Search(quiet: true)); }
protected override double GetValueImpl(PAD.Planner.IState state) { Problem.SetInitialState(state); solver.SetProblem(Problem); var solutionLength = solver.Search(quiet: true); return(solutionLength); }
public static void solveDomain(string domainFolder, DomainDependentSolver solver, bool submitPlans = false) { Console.WriteLine("problem\tminBound\tmaxBound\tplanLength"); var plansFolder = Path.Combine(domainFolder, "plans"); if (!Directory.Exists(plansFolder)) { Directory.CreateDirectory(plansFolder); } foreach (var item in Directory.EnumerateFiles(domainFolder)) { if (Path.GetExtension(item) != ".sas") { continue; } solver.SetProblem(new Problem(item, false)); var planLength = (int)solver.Search(quiet: true); var problemInfo = File.ReadAllLines(Path.Combine(domainFolder, "pddl", "_problemInfo", Path.ChangeExtension(Path.GetFileName(item), "txt"))).Distinct().Select( line => line.Split('\t').ToList()).ToDictionary(t => t.First(), t => t.Last()); int minBound = 0; if (!int.TryParse(problemInfo["lowerBound"], out minBound)) { minBound = 0; } int maxBound = int.MaxValue; if (!int.TryParse(problemInfo["upperBound"], out maxBound)) { maxBound = int.MaxValue; } int problemID = 0; if (!problemInfo.ContainsKey("problemID") || !int.TryParse(problemInfo["problemID"], out problemID)) { problemID = -1; } Console.WriteLine(Path.GetFileNameWithoutExtension(item) + "\t" + minBound + "\t" + maxBound + "\t" + planLength); var planFile = Path.Combine(plansFolder, Path.ChangeExtension(Path.GetFileName(item), "txt")); if (!File.Exists(planFile) || planLength <= File.ReadAllLines(planFile).Count()) { File.WriteAllLines(planFile, solver.getPDDLPlan()); } if (submitPlans && planLength < maxBound) { var plan = File.ReadAllLines(planFile).ToList(); Console.WriteLine("Submiting plan..."); Console.WriteLine("response:"); Console.WriteLine("-------------"); var response = PlanSubmission.submitPlan(plan, problemID); Console.WriteLine(response); Console.WriteLine("-------------"); } } }
List <IState> findGoalPath() { if (domainSolver.canFindPlans) { domainSolver.Search(); var plan = domainSolver.getPDDLPlan(); var sasPlan = plan.Select(s => s.Replace("(", "").Replace(")", "")).Select(s => (PAD.Planner.IOperator)problem.Operators.Where(op => op.GetName() == s).Single()); SolutionPlan p = new SolutionPlan(problem.GetInitialState(), sasPlan); return(p.GetStatesSequence().Select(state => (IState)state).ToList()); } goalPathFinder.Start(); return(goalPathFinder.GetSolutionPlan().GetStatesSequence().Select(state => (IState)state).ToList()); }