예제 #1
0
파일: DBCreator.cs 프로젝트: otaTrunda/PADD
        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);
        }
예제 #2
0
파일: DBCreator.cs 프로젝트: otaTrunda/PADD
        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.
            }
        }
예제 #3
0
 public FFNetHeuristicFactory(string featuresGeneratorPath, string savedNetworkPath, bool useFFHeuristicAsFeature, TargetTransformationType targetTransformation, DomainDependentSolver solver,
                              string generatorUsedForStoringStates) :
     this(featuresGeneratorPath, savedNetworkPath, useFFHeuristicAsFeature, targetTransformation)
 {
     this.solver = solver;
     this.generatorUsedForStoringStates = generatorUsedForStoringStates;
 }
예제 #4
0
        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("-------------");
                }
            }
        }
예제 #5
0
파일: DBCreator.cs 프로젝트: otaTrunda/PADD
 public RandomWalksFromGoalPathStateSpaceEnumerator(Problem problem, DomainDependentSolver domainDependentSolver)
     : base(problem)
 {
     domainDependentSolver.SetProblem(problem);
     this.goalPathFinder  = new HillClimbingSearch(problem, new HeuristicWrapper(domainDependentSolver));
     domainSolver         = domainDependentSolver;
     goalPath             = findGoalPath();
     StateSpaceEnumeratos = goalPath.Select(s =>
     {
         var enume          = new RandomWalkStateSpaceEnumerator(problem);
         enume.initialState = s;
         return(enume);
     }).ToList();
 }
예제 #6
0
        public static void createStatesDB(string problemFile, DomainDependentSolver domainSpecificSolver)
        {
            var sasProblem = new Problem(problemFile, false);

            PADD.StatesDB.StatesEnumerator e = new RandomWalksFromGoalPathStateSpaceEnumerator(sasProblem, domainSpecificSolver);
            DBCreator c = new DBCreator(e);

            if (domainSpecificSolver is PADD.DomainDependentSolvers.VisitAll.VisitAllSolver)
            {
                var goalPath = ((RandomWalksFromGoalPathStateSpaceEnumerator)e).goalPath;
                ((PADD.DomainDependentSolvers.VisitAll.VisitAllSolver)domainSpecificSolver).drawPlan(goalPath);
            }

            c.createDB(problemFile, domainSpecificSolver, 100000, TimeSpan.FromHours(1));
            var states = c.DB.getAllElements().ToList();

            Trie <int> t = Trie <int> .load(c.getDBFilePath(problemFile),
                                            s => int.Parse(s));

            states = t.getAllElements().ToList();

            var realStates = states.Select(s => (State.Parse(s.key), s.value)).ToList();
        }
예제 #7
0
        public SpecificSolverHeuristic(PAD.Planner.IProblem problem, DomainType domain) : base(problem)
        {
            switch (domain)
            {
            case DomainType.Zeno:
                solver = new PADD.DomainDependentSolvers.Zenotravel.ZenotravelSolver(20, 5);
                break;

            case DomainType.VisitAll:
                solver = new PADD.DomainDependentSolvers.VisitAll.VisitAllSolver();
                break;

            case DomainType.Blocks:
                solver = new PADD.DomainDependentSolvers.BlocksWorld.BlocksWorldSolver();
                break;

            case DomainType.TSP:
                throw new Exception();

            default:
                throw new Exception();
            }
            this.Statistics.DoMeasure = false;
        }
예제 #8
0
        public static void createStatesDBForDomain(string domainFolder, string outputFolder, DomainDependentSolver solver, long totalSamples, bool storeObjectGraphs = true)
        {
            var  problemFiles   = PADDUtils.FileSystemUtils.enumerateProblemFiles(domainFolder).ToList();
            long samplesPerFile = totalSamples / problemFiles.Count;

            PADDUtils.FileSystemUtils.createDirIfNonExisting(outputFolder);
            long samplesGenerated = 0;
            long toBeGenerated    = samplesPerFile * problemFiles.Count;

            using (var writter = new StreamWriter(Path.Combine(outputFolder, "samples.tsv")))
            {
                long currentID = 1;
                writter.WriteLine("_ID\ttarget\tstate\tdomain\tproblem");                   //writing header

                foreach (var item in problemFiles)
                {
                    var sasProblem   = new Problem(item, false);
                    var initialState = sasProblem.InitialState;
                    PADD.StatesDB.StatesEnumerator e = new RandomWalksFromGoalPathStateSpaceEnumerator(sasProblem, solver);
                    DBCreator c       = new DBCreator(e);
                    var       samples = c.createSamples(item, solver, samplesPerFile, TimeSpan.FromHours(5));
                    foreach (var sample in samples)
                    {
                        samplesGenerated++;
                        if (samplesGenerated % 100 == 0)
                        {
                            Console.WriteLine("Samples generated: " + samplesGenerated + " out of " + toBeGenerated + " (" + ((double)samplesGenerated / toBeGenerated * 100).ToString("0.00") + " %");
                        }

                        writter.Write(currentID + "\t");
                        writter.Write(sample.val + "\t");
                        writter.Write(sample.key + "\t");
                        writter.Write(Path.GetFileName(domainFolder) + "\t");
                        writter.WriteLine(Path.GetFileName(item));
                        if (storeObjectGraphs)
                        {
                            IState s = State.Parse(sample.key);
                            sasProblem.SetInitialState(s);
                            var graph = KnowledgeExtractionGraphs.computeObjectGraph(sasProblem).toMSAGLGraph();

                            /*
                             * Console.WriteLine(sample.key + "\t" + s.toStringWithMeanings());
                             * Utils.GraphVisualization.GraphVis.showGraph(graph);
                             */

                            string graphPath = Path.Combine(outputFolder, "graphs", currentID.ToString() + ".bin");
                            PADDUtils.FileSystemUtils.createDirIfNonExisting(Path.Combine(outputFolder, "graphs"));
                            using (var stream = new FileStream(graphPath, FileMode.Create))
                            {
                                graph.WriteToStream(stream);
                            }
                            sasProblem.SetInitialState(initialState);
                        }
                        currentID++;
                    }
                }
            }
        }
예제 #9
0
파일: DBCreator.cs 프로젝트: otaTrunda/PADD
 public HeuristicWrapper(DomainDependentSolver solver) : base(null)
 {
     this.solver = solver;
 }