Beispiel #1
0
        public static Graph MakeTree(int nodeCount, int arity)
        {
            Graph graph = new Graph();

            graph.AddNode(new BaseNode());
            graph.AddChildren(arity, graph.NodeCount - 1);

            Queue <int> latestIndex = new Queue <int>();

            for (int i = 0; i < arity; ++i)
            {
                latestIndex.Enqueue(graph.NodeCount - 1 - i);
            }

            while (graph.NodeCount < nodeCount)
            {
                if (latestIndex.Count <= 0)
                {
                    break;
                }
                int parentIndex = latestIndex.Peek();

                if (graph.adjacencyList[parentIndex].Count > arity)
                {
                    latestIndex.Dequeue();
                    continue;
                }
                graph.AddChildren(1, parentIndex);
                latestIndex.Enqueue(graph.NodeCount - 1);
            }
            return(graph);
        }
Beispiel #2
0
 public static Graph MakeHub(int childrenCount)
 {
     Graph graph = new Graph();
     graph.AddNode(new BaseNode());
     graph.AddChildren( childrenCount, 0 );
     return graph;
 }
Beispiel #3
0
        public static Graph MakeHub(int childrenCount)
        {
            Graph graph = new Graph();

            graph.AddNode(new BaseNode());
            graph.AddChildren(childrenCount, 0);
            return(graph);
        }
Beispiel #4
0
        public static Graph MakeTree(int nodeCount, int arity)
        {
            Graph graph = new Graph();

            graph.AddNode(new BaseNode());
            graph.AddChildren(arity, graph.NodeCount - 1);

            Queue<int> latestIndex = new Queue<int>();
            for (int i = 0; i < arity; ++i)
            {
                latestIndex.Enqueue(graph.NodeCount - 1 - i);
            }

            while (graph.NodeCount < nodeCount)
            {
                if (latestIndex.Count <= 0)
                {
                    break;
                }
                int parentIndex = latestIndex.Peek();

                if (graph.adjacencyList[parentIndex].Count > arity)
                {
                    latestIndex.Dequeue();
                    continue;
                }
                graph.AddChildren(1, parentIndex);
                latestIndex.Enqueue(graph.NodeCount - 1);
            }
            return graph;
        }