Ejemplo n.º 1
0
        public static Graph CreateRandomGraph(int maxSize)
        {
            var size   = GoodRandom.Next(maxSize) + 1;
            var matrix = new bool[size, size];

            for (var i = 0; i < size; i++)
            {
                for (var j = 0; j < i; j++)
                {
                    if (GoodRandom.Bool())
                    {
                        matrix[i, j] = matrix[j, i] = true;
                    }
                }
            }
            return(new Graph(matrix));
        }
Ejemplo n.º 2
0
        private void AddRandomEdges(int numberOfEdgesToAdd)
        {
            var possibleEdges = GetPossibleEdges();

            if (possibleEdges.Count > 0)
            {
                for (var i = 0; i < numberOfEdgesToAdd; i++)
                {
                    var edge = possibleEdges[GoodRandom.Next(possibleEdges.Count)];
                    AdjacencyMatrix[edge.from, edge.to] = 1;
                    AdjacencyMatrix[edge.to, edge.from] = 1;
                    possibleEdges.Remove(edge);
                    if (possibleEdges.Count <= 0)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void RemoveRandomEdges(int numberOfEdgesToRemove)
        {
            var edges = GetEdges();

            if (edges.Count > 0)
            {
                for (var i = 0; i < numberOfEdgesToRemove; i++)
                {
                    var edge = edges[GoodRandom.Next(edges.Count)];
                    AdjacencyMatrix[edge.from, edge.to] = 0;
                    AdjacencyMatrix[edge.to, edge.from] = 0;
                    edges.Remove(edge);
                    if (edges.Count <= 0)
                    {
                        break;
                    }
                }
            }
        }