コード例 #1
0
        public static void ComposeHTNs(int hMax, Dictionary <Composite, List <Decomposition> > Methods)
        {
            // for each height to ground a composite operator
            for (int h = 0; h < hMax; h++)
            {
                // For each (composite operator, method) pair
                foreach (var compositepair in Methods)
                {
                    // Create a new list of composites that will be assembled in this iteration
                    var compList = new List <Composite>();

                    // for each legal decomposition of this composite operator
                    foreach (var decomp in compositepair.Value)
                    {
                        // Create a list of ground decompositions
                        var groundDecomps = decomp.Compose(h);

                        // for each ground decomposition
                        foreach (var gdecomp in groundDecomps)
                        {
                            // clone composite task
                            var comp = compositepair.Key.PseudoClone();
                            comp.Name = decomp.Name;
                            // Set height of composite step
                            comp.Height = h + 1;

                            // Assign method to composite step
                            var numUnBound = comp.ApplyDecomposition(gdecomp);

                            // If all terms are bound, then add as is.
                            if (numUnBound == 0)
                            {
                                compList.Add(comp);
                            }
                            // Otherwise, bind the remaining unbound terms
                            else if (numUnBound > 0)
                            {
                                // Remove unbound args
                                comp.RemoveRemainingArgs();

                                compList.Add(comp);
                            }
                        }
                    }
                    // For each newly created composite step, add to the library.
                    foreach (var comp in compList)
                    {
                        comp.GoalStep.OpenConditions = comp.GoalStep.Preconditions;

                        GroundActionFactory.InsertOperator(comp as IOperator);
                    }
                }
            }
        }
コード例 #2
0
        public static void ComposeHTNs(int hMax, Tuple <Composite, List <Decomposition> > Methods)
        {
            for (int h = 0; h < hMax; h++)
            {
                var compList = new List <Composite>();
                foreach (var decomp in Methods.Second)
                {
                    var groundDecomps = decomp.Compose(h);

                    foreach (var gdecomp in groundDecomps)
                    {
                        // clone composite task
                        var comp = Methods.First.PseudoClone();

                        // Set height of composite step
                        comp.Height = h + 1;

                        // Assign method to composite step
                        var numUnBound = comp.ApplyDecomposition(gdecomp);

                        // If all terms are bound, then add as is.
                        if (numUnBound == 0)
                        {
                            compList.Add(comp);
                        }
                        // Otherwise, bind the remaining unbound terms
                        else
                        {
                            // NEW METHOD: Remove unbound args
                            comp.RemoveRemainingArgs();
                            compList.Add(comp);

                            // OLD METHOD: There could be more than one way to bind remaining terms
                            //var boundComps = comp.GroundRemainingArgs(numUnBound);
                            //foreach (var bc in boundComps)
                            //{
                            //    // Add each possible way to bind remaining terms
                            //    compList.Add(bc);
                            //}
                        }
                    }
                }
                // For each newly created composite step, add to the library.
                foreach (var comp in compList)
                {
                    GroundActionFactory.InsertOperator(comp as IOperator);
                }
            }
        }