示例#1
0
        public Graph Generate(int verticesNumber, int degree)
        {
            #region Initialize Graph

            var graph = new Graph();
            graph.Edges.Clear();
            for (var i = 0; i < verticesNumber; i++)
            {
                graph.Edges.Add(new List <int>(verticesNumber));
                for (var j = 0; j < verticesNumber; j++)
                {
                    graph.Edges[i].Add(Graph.Infinity);
                }

                while (graph.Edges[i].Count(wight => wight == Graph.DefaultWeight) != degree)
                {
                    graph.Edges[i][_random.Next(verticesNumber)] = Graph.DefaultWeight;
                }
            }

            #endregion

            graph.Degree = GraphHelper.CalculateAverageGraphDegree(graph.Edges);
            return(graph);
        }
示例#2
0
        public Graph Generate()
        {
            #region Generate De Bruijn vertices

            var verticesNumber   = Convert.ToInt32(Math.Pow(_base, _bitness));
            var deBruijnVertices = new List <DeBruijnVertex>(verticesNumber);
            AddDeBruijnVertex(deBruijnVertices, new string('0', _bitness));

            #endregion

            #region Initialize Graph

            var graph = new Graph();
            graph.Edges.Clear();
            for (var i = 0; i < verticesNumber; i++)
            {
                graph.Edges.Add(new List <int>(verticesNumber));
                for (var j = 0; j < verticesNumber; j++)
                {
                    graph.Edges[i].Add(Graph.Infinity);
                }
            }

            #endregion

            foreach (DeBruijnVertex deBruijnVertex in deBruijnVertices)
            {
                foreach (string connectedWithName in deBruijnVertex.ConnectedWith.Where(v => v != deBruijnVertex.Name))
                {
                    int connectedWithIdx = deBruijnVertices.Single(v => v.Name == connectedWithName).Index;
                    graph.Edges[deBruijnVertex.Index][connectedWithIdx] = Graph.DefaultWeight;
                }

                foreach (DeBruijnVertex clusterVertex in deBruijnVertices.Where(v => v.Value == deBruijnVertex.Value && v.Name != deBruijnVertex.Name))
                {
                    graph.Edges[deBruijnVertex.Index][clusterVertex.Index] = 1;
                }
            }

            graph.Degree = GraphHelper.CalculateAverageGraphDegree(graph.Edges);
            return(graph);
        }