예제 #1
0
 private static void AddStartNode(Graph graph, EdgeThree edgeThree)
 {
     graph.AddNode(0);
     graph.AddNode(1);
     graph.AddEdge(1, 0);
     edgeThree.AddEdge(1, 0);
 }
예제 #2
0
        static void Main(string[] args)
        {
            var nodeThree = new EdgeThree(NodeCount); //это дерево отрезков, с ним за log(n) можно узнавать номер вершины по случайному числу
            var graph     = new Graph();

            AddStartNode(graph, nodeThree);
            MakeThree(nodeThree, graph);
            File.WriteAllLines("graph.dot", CreateDotGraph(graph));                           //граф получился уродский...
            Chart.ShowHistogram("Graph", DataAnalysis.ToHistogramData(graph.GetGraphInfo())); //диаграмка тоже :(
        }
예제 #3
0
 private static void MakeThree(EdgeThree edgeThree, Graph graph)
 {
     for (var currentNode = 2; currentNode < NodeCount; currentNode++)
     {
         graph.AddNode(currentNode);
         var used = new HashSet <int>(new[] { currentNode });
         for (var i = 0; i < M; i++)
         {
             var randomNumber = GetRandomNumber(edgeThree);
             var selectedNode = edgeThree.GetIndexForRandomNumber(randomNumber);
             if (used.Contains(selectedNode))
             {
                 selectedNode = SelectEmptyNode(selectedNode, graph);
             }
             used.Add(selectedNode);
             graph.AddEdge(currentNode, selectedNode);
             edgeThree.AddEdge(currentNode, selectedNode);
         }
     }
 }
예제 #4
0
        private static int GetRandomNumber(EdgeThree edgeThree)
        {
            var random = new Random();

            return(random.Next(edgeThree.GetTop()) + 1);
        }