Exemple #1
0
        public static Graph RandGraph(int V, int E, int seed = -1)
        {
            if (seed == -1)
            {
                seed = DateTime.Now.Millisecond;
            }
            Graph G = new Graph();

            G.IsDirected = false;

            Random random = new Random(seed);
            double p      = 2 * E / V / (V - 1.0);

            for (int i = 0; i < V; i++)
            {
                G.CreateVertex(i);
                for (int j = 0; j < i; j++)
                {
                    if (random.NextDouble() < p)
                    {
                        G.InsertEdge(i, j, G.IsDirected);
                    }
                }
            }

            return(G);
        }
Exemple #2
0
        public static Graph Read(TextReader reader)
        {
            Graph  G    = new Graph();
            string line = reader.ReadLine();

            for (int i = 0; i < int.Parse(line); i++)
            {
                G.CreateVertex(i);
            }


            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(',');
                G.InsertEdge(int.Parse(tokens[0]) - 1, int.Parse(tokens[1]) - 1, false);
            }

            return(G);
        }
Exemple #3
0
        public static Graph Read(TextReader reader)
        {
            Graph G = new Graph();
            string line = reader.ReadLine();

            for (int i = 0; i < int.Parse(line); i++)
                G.CreateVertex(i);

            while ((line = reader.ReadLine()) != null)
            {
                string[] tokens = line.Split(',');
                G.InsertEdge(int.Parse(tokens[0]) - 1, int.Parse(tokens[1]) - 1, false);
            }

            return G;
        }
Exemple #4
0
        public static Graph RandGraph(int V, int E, int seed = -1)
        {
            if (seed == -1)
                seed = DateTime.Now.Millisecond;
            Graph G = new Graph();
            G.IsDirected = false;

            Random random = new Random(seed);
            double p = 2 * E / V / (V - 1.0);
            for (int i = 0; i < V; i++)
            {
                G.CreateVertex(i);
                for (int j = 0; j < i; j++)
                    if (random.NextDouble() < p)
                        G.InsertEdge(i, j, G.IsDirected);
            }

            return G;
        }