Exemple #1
0
        public static KnowledgeHolder create(PAD.Planner.PDDL.Problem problem)
        {
            KnowledgeHolder h = new KnowledgeHolder();

            h.predConstGraph = new PredicateConstantGraph(problem);
            return(h);
        }
Exemple #2
0
        public static void visualizePDDLKnowledgeGraphs(string PDDLDomainFile, string PDDLProblemFile)
        {
            var             problem = new PAD.Planner.PDDL.Problem(PDDLDomainFile, PDDLProblemFile);
            KnowledgeHolder h       = KnowledgeHolder.create(problem);

            h.visualize();
        }
Exemple #3
0
        /// <summary>
        /// Gets SaSproblem and produces a PDDLProblem description that
        /// is equivalent to current SASState. It returns content of a PDDL problem file (that when parsed would have the same initial state as the SaSProblem.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="s"></param>
        /// <returns></returns>
        public static PAD.Planner.PDDL.Problem translateSASProblemToPDDL(PAD.Planner.SAS.Problem s)
        {
            var    pddlProblemPath = PADDUtils.FileSystemUtils.getPDDLProblemPath(s.GetInputFilePath());
            string originalText    = System.IO.File.ReadAllText(pddlProblemPath.problemFile).Replace("(:INIT", "(:init");

            string PDDLStateInitRegion = originalText.Split(new string[] { "(:init" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).First().
                                         Split(new string[] { "(:" }, StringSplitOptions.RemoveEmptyEntries).First();
            List <string> predicates = PDDLStateInitRegion.Split('(').Select(r => r.Replace(")", "").Trim()).Where(q => !string.IsNullOrWhiteSpace(q)).ToList();

            predicates = predicates.Select(q =>
            {
                int firstSpace = q.IndexOf(" ");
                if (firstSpace < 0)
                {
                    firstSpace = q.Length;
                    return(q.Insert(firstSpace, "("));
                }
                else
                {
                    return(q.Remove(firstSpace, 1).Insert(firstSpace, "("));
                }
            }).Select(q => q.Replace(" ", ", ") + ")").ToList();

            List <string> newPredicates = new List <string>();
            var           initialState  = s.InitialState;

            for (int i = 0; i < initialState.GetAllValues().Length; i++)
            {
                List <string> corresponding = predicates.Where(q => s.Variables[i].Values.Contains("Atom " + q.ToLower())).ToList();
                predicates.RemoveAll(p => corresponding.Contains(p));
                newPredicates.Add(s.Variables[i].Values[initialState.GetAllValues()[i]]);
            }
            predicates.AddRange(newPredicates.Where(x => x.Substring(0, "Atom ".Length) == "Atom "));
            predicates = predicates.Select(p => p.Replace("Atom ", "").Replace("(", " ").Replace(",", "").Replace(")", "").Trim()).ToList();
            string tempFileName = System.IO.Path.GetTempFileName();

            string text = originalText.Split(new string[] { "(:init" }, StringSplitOptions.RemoveEmptyEntries).First() + "(:init\n";

            text += string.Join("\n", predicates.Select(q => "\t(" + q + ")"));
            text += "\n)\n(:";
            text += string.Join("(:", originalText.Split(new string[] { "(:init" }, StringSplitOptions.RemoveEmptyEntries).Skip(1).First().Split(new string[] { "(:" }, StringSplitOptions.RemoveEmptyEntries).Skip(1));

            System.IO.File.WriteAllText(tempFileName, text);

            var result = new PAD.Planner.PDDL.Problem(pddlProblemPath.domainFile, tempFileName);

            System.IO.File.Delete(tempFileName);
            return(result);
        }
 public void Train(PAD.Planner.PDDL.Problem p)
 {
 }