Beispiel #1
0
        private static TextTree PlantTree(string treeId, TreeSpecification ts, Random r)
        {
            var root = new TreeNode {
                Symbol = ts.Lables[r.Next(0, ts.Lables.Count)]
            };

            root.SetParent(null);

            Germinate(root, ts.MaxDepth, ts.MaxDegree, ts.Lables, r);

            var mytree = new TextTree {
                TreeId = treeId, Root = root
            };

            return(mytree);
        }
Beispiel #2
0
        public static List <ITextTree> Generate(ForestSpecification fs, NodeSymbol backTrack)
        {
            if (!IsForestSpecificationValid(fs, backTrack))
            {
                return(null);
            }

            var forest = new List <ITextTree>();
            var ts     = new TreeSpecification(fs.Labels)
            {
                MaxDepth = fs.MaxTreeDepth, MaxDegree = fs.MaxDegree
            };

            for (var i = 0; i < fs.NumberOfTrees; i++)
            {
                var tree = PlantTree(string.Format("{0:00000000}", i), ts, Random);
                forest.Add(tree);
            }

            return(forest);
        }