예제 #1
0
파일: TestAll.cs 프로젝트: drwiner/GDPOPS
        public static void TestBenchmarks()
        {
            var domainNames = new List <string>()
            {
                "arth", "batman"
            };

            foreach (var dn in domainNames)
            {
                var testDomainDirectory = Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\domain.pddl";
                var testDomain          = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\domain.pddl", PlanType.PlanSpace);
                var testProblem         = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + dn + @"\prob01.pddl");

                ProblemFreezer PF = new ProblemFreezer(dn, testDomainDirectory, testDomain, testProblem);
                PF.Serialize();

                var directory = @"D:\Documents\Frostbow\Benchmarks\Results\";
                var cutoff    = 6000f;
                var k         = 1;

                var initPlan = PlanSpacePlanner.CreateInitialPlan(PF);

                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E1(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E2(new AddReuseHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E3(new AddReuseHeuristic()), k, cutoff, directory, 0);
                //RunPlanner(initPlan.Clone() as IPlan, new DFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 0);
                RunPlanner(initPlan.Clone() as IPlan, new BFS(), new Nada(new ZeroHeuristic()), k, cutoff, directory, 0);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public static void RunPlanner(IPlan initPi, ISearch SearchMethod, ISelection SelectMethod, int k, float cutoff, string directoryToSaveTo, int problem)
 {
     var POP = new PlanSpacePlanner(initPi, SelectMethod, SearchMethod, true)
     {
         directory     = directoryToSaveTo,
         problemNumber = problem,
     };
     var Solutions = POP.Solve(k, cutoff);
 }
예제 #5
0
        public static void RunPlanner(IPlan initPi, ISearch SearchMethod, ISelection SelectMethod, float cutoff, string directoryToSaveTo, int problem)
        {
            var POP = new PlanSpacePlanner(initPi, SelectMethod, SearchMethod, true)
            {
                directory     = directoryToSaveTo,
                problemNumber = problem,
            };
            var Solutions = POP.Solve(1, cutoff);

            if (Solutions != null)
            {
                Console.WriteLine(Solutions[0].ToStringOrdered());
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
        public static void RunPlanner(IPlan initPi, ISearch SearchMethod, ISelection SelectMethod, int k, float cutoff, string directoryToSaveTo, int problem)
        {
            // Create a planner object to run this instance
            var POP = new PlanSpacePlanner(initPi, SelectMethod, SearchMethod, true)
            {
                directory     = directoryToSaveTo,
                problemNumber = problem,
            };

            // Return a list of k solutions
            var Solutions = POP.Solve(k, cutoff);

            // Print the first solution to console
            if (Solutions != null)
            {
                Console.Write(Solutions[0].ToStringOrdered());
            }
        }
예제 #8
0
        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);
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.Write("hello world\n");
            var directory = Parser.GetTopDirectory() + @"/Results/";
            var cutoff    = 6000f;
            var k         = 1;

            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");

            var problemFreezer = new ProblemFreezer(testDomainName, testDomainDirectory, testDomain, testProblem);

            //problemFreezer.Serialize();
            problemFreezer.Deserialize();
            var initPlan = PlanSpacePlanner.CreateInitialPlan(problemFreezer);

            RunPlanner(initPlan.Clone() as IPlan, new ADstar(), new E0(new AddReuseHeuristic()), k, cutoff, directory, 1);
            //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);
        }
예제 #11
0
        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);
             */
        }
예제 #12
0
    // 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]);
    }