示例#1
0
 public Spring(TNode start, TNode end, double length, double stiffness)
 {
     this.Start = start;
     this.End = end;
     this.Length = length;
     this.Stiffness = stiffness;
 }
示例#2
0
        /// <summary>
        /// Generates a random tree
        /// </summary>
        /// <param name="depth">desired depth of tree</param>
        /// <returns>
        /// A newly generated Tree of specified degree "maxBreadth"
        /// </returns>
        public static TNode Generate(RadialTreeGraph.TraversalType gen_mechanism,
            int depth,
            int max_breadth,
            int num_first_children = -1,
            int max_nodes = -1)
        {
            TNode Root = new TNode { Level = 1 };

            Random rnd = new Random();
            int breadth;
            int i;
            TNode child;
            var k = new RadialTreeGraph.TraversalListIDS<TNode>(gen_mechanism);
            var visited = new Hashtable();
            bool finished = false;
            TNode c;
            int count = 0;

            k.Add(Root);

            while (k.Count > 0 && finished == false)
            {
                c = k.Take();
                // generate new level of arbirary children until desired depth is reached

                if (gen_mechanism == RadialTreeGraph.TraversalType.DepthFirst || !visited.ContainsKey(c))
                {
                    if (gen_mechanism == RadialTreeGraph.TraversalType.BreadthFirst)
                        visited.Add(c, 0);

                    if (c.Level == 1)
                    {
                        if (num_first_children == -1)
                        {
                            breadth = rnd.Next(1, max_breadth + 1);
                        }
                        else
                        {
                            breadth = num_first_children;
                        }
                    }
                    else
                    {
                        breadth = rnd.Next(1, max_breadth + 1);
                    }

                    for (i = 0; i < breadth; i++)
                    {
                        child = new TNode();
                        child.Parent = c;
                        child.Level = c.Level + 1;
                        child.ChildIndex = i;

                        count++;
                        c.Children.Add(child);

                        k.Add(child);
                    }
                }

                // finished when reached desired number of nodes or reached desired depth
                if (max_nodes > 0)
                {
                    finished = count >= max_nodes;
                }
                else
                {
                    finished = c.Level == depth;
                }
            }

            return Root;
        }
示例#3
0
        public void Tree()
        {
            //root = new TNode();
            //firstChild = new TNode();
            //root.Color = Color.Green;
            //firstChild.Color = Color.Cyan;
            //firstChild.Parent = root;
            //root.Children.Add(firstChild);
            //springs.Add(new Spring(root, firstChild, rest_distance, stiffness));

            root = Generate(gen_type,
                            depth: 15,
                            max_breadth: 2, // 40,100
                            num_first_children: -1,
                            max_nodes: -1);

            root.Traverse((TNode c) =>
            {
                if (c.Parent != null)
                {
                    c.Color = Color.Cyan;
                    c.Parent.Color = Color.Green;

                    springs.Add(new Spring(c.Parent, c, rest_distance, stiffness));
                }
            });
        }