public IEnumerator <object[]> GetEnumerator()
        {
            for (int i = LowerBound; i < UpperBound; ++i)
            {
                string testCase = i.ToString("D2", CultureInfo.InvariantCulture);

                using TextReader textReader = IndexedGraphs.GetTextReader(testCase);
                if (textReader == TextReader.Null)
                {
                    continue;
                }

                var    edges       = IndexedEdgeListParser.ParseEdges(textReader).ToList();
                int    vertexCount = edges.Count == 0 ? 0 : edges.Select(e => Math.Max(e.Tail, e.Head)).Max() + 1;
                string description = $"{{{nameof(testCase)}: {testCase}}}";
                GraphDefinitionParameter parameter = new(vertexCount, edges, description);
                yield return(new object[] { parameter });
            }

            for (int i = 1; i < 7; ++i)
            {
                double power       = 0.5 * i;
                int    vertexCount = (int)Math.Ceiling(Math.Pow(10.0, power));
                foreach (double densityPower in s_densityPowers)
                {
                    List <Endpoints> edges = new();
                    GraphHelpers.GenerateEdges(vertexCount, densityPower, edges);
                    string description =
                        $"{{{nameof(vertexCount)}: {vertexCount.ToString(F)}, {nameof(densityPower)}: {densityPower.ToString(F)}}}";
                    GraphDefinitionParameter parameter = new(vertexCount, edges, description);
                    yield return(new object[] { parameter });
                }
            }
        }
Example #2
0
        private static void Main()
        {
            SimpleIncidenceGraph.Builder builder = new(0, 31);

            using (TextReader textReader = IndexedGraphs.GetTextReader("09"))
            {
                IEnumerable <Endpoints> edges = IndexedEdgeListParser.ParseEdges(textReader);
                foreach (Endpoints edge in edges)
                {
                    builder.Add(edge.Tail, edge.Head);
                }
            }

            SimpleIncidenceGraph graph = builder.ToGraph();

            Console.Write($"{nameof(graph.VertexCount)}: {graph.VertexCount.ToString(F)}");
            Console.WriteLine($", {nameof(graph.EdgeCount)}: {graph.EdgeCount.ToString(F)}");

            TextWriter w = Console.Out;

            EnumerableDfs <SimpleIncidenceGraph, int, Endpoints, ArraySegment <Endpoints> .Enumerator> dfs = default;

            w.WriteLine($"digraph \"{dfs.GetType().Name}\" {{");
            w.WriteLine("  node [shape=circle style=dashed fontname=\"Times-Italic\"]");

            // Enumerate vertices.
            for (int v = 0; v < graph.VertexCount; ++v)
            {
                w.Write(v == 0 ? "  " : " ");
                w.Write(V(v));
            }

            w.WriteLine();
Example #3
0
        private static void DemoUndirected()
        {
            UndirectedIndexedIncidenceGraph.Builder builder = new(10);

            using (TextReader textReader = IndexedGraphs.GetTextReader("05"))
            {
                IEnumerable <Endpoints> edges = IndexedEdgeListParser.ParseEdges(textReader);
                foreach (Endpoints edge in edges)
                {
                    builder.Add(edge.Tail, edge.Head);
                }
            }

            UndirectedIndexedIncidenceGraph graph = builder.ToGraph();

            Console.Write($"{nameof(graph.VertexCount)}: {graph.VertexCount}");
            Console.WriteLine($", {nameof(graph.EdgeCount)}: {graph.EdgeCount}");

            if (graph.VertexCount <= 0)
            {
                return;
            }

            PrintIncidentEdges(graph, 0);

            if (graph.VertexCount == 1)
            {
                return;
            }

            PrintIncidentEdges(graph, graph.VertexCount - 1);
Example #4
0
        public IEnumerator <object[]> GetEnumerator()
        {
            for (int i = LowerBound; i < UpperBound; ++i)
            {
                string        testCase = i.ToString("D2", CultureInfo.InvariantCulture);
                TGraphBuilder builder  = CreateGraphBuilder(0);

                using (TextReader textReader = IndexedGraphs.GetTextReader(testCase))
                {
                    if (textReader == TextReader.Null)
                    {
                        continue;
                    }

                    IEnumerable <Endpoints> edges = IndexedEdgeListParser.ParseEdges(textReader);
                    foreach (Endpoints edge in edges)
                    {
                        builder.TryAdd(edge.Tail, edge.Head, out _);
                    }
                }

                TGraph graph          = builder.ToGraph();
                string description    = $"{{{nameof(testCase)}: {testCase}}}";
                var    graphParameter = GraphParameter.Create(graph, description);
                yield return(new object[] { graphParameter });
            }

            {
                const int     vertexCount  = 1;
                const double  densityPower = 1.0;
                TGraphBuilder builder      = CreateGraphBuilder(1);
                GraphHelpers.PopulateIncidenceGraphBuilder <TGraph, TEdge, TEdges, TGraphBuilder>(
                    builder, vertexCount, densityPower);
                TGraph graph       = builder.ToGraph();
                string description =
                    $"{{{nameof(vertexCount)}: {vertexCount.ToString(F)}, {nameof(densityPower)}: {densityPower.ToString(F)}}}";
                var graphParameter = GraphParameter.Create(graph, description);
                yield return(new object[] { graphParameter });
            }

            for (int i = 1; i < 7; ++i)
            {
                double power       = 0.5 * i;
                int    vertexCount = (int)Math.Ceiling(Math.Pow(10.0, power));
                foreach (double densityPower in GraphHelpers.DensityPowers)
                {
                    TGraphBuilder builder = CreateGraphBuilder(1);
                    GraphHelpers.PopulateIncidenceGraphBuilder <TGraph, TEdge, TEdges, TGraphBuilder>(
                        builder, vertexCount, densityPower);
                    TGraph graph       = builder.ToGraph();
                    string description =
                        $"{{{nameof(vertexCount)}: {vertexCount.ToString(F)}, {nameof(densityPower)}: {densityPower.ToString(F)}}}";
                    var graphParameter = GraphParameter.Create(graph, description);
                    yield return(new object[] { graphParameter });
                }
            }
        }
Example #5
0
        private static void DemoShuffle()
        {
            IndexedIncidenceGraph.Builder builder = new(10);

            using (TextReader textReader = IndexedGraphs.GetTextReader("08"))
            {
                IEnumerable <Endpoints> edges = IndexedEdgeListParser.ParseEdges(textReader);
                foreach (Endpoints edge in edges)
                {
                    builder.Add(edge.Tail, edge.Head);
                }
            }

            IndexedIncidenceGraph graph = builder.ToGraph();

            Console.Write($"{nameof(graph.VertexCount)}: {graph.VertexCount.ToString(F)}");
            Console.WriteLine($", {nameof(graph.EdgeCount)}: {graph.EdgeCount.ToString(F)}");

            TextWriter w = Console.Out;

            w.WriteLine("digraph Shuffled {");
            w.WriteLine("  node [shape=circle fontname=\"Times-Italic\"]");

            // Enumerate vertices.
            for (int v = 0; v < graph.VertexCount; ++v)
            {
                w.Write(v == 0 ? "  " : " ");
                w.Write(V(v));
            }

            w.WriteLine();

            int[] permutation = Enumerable.Range(0, graph.EdgeCount)
                                .OrderBy(i => new Random(i).Next()).ToArray();

            for (int i = 0; i < graph.EdgeCount; ++i)
            {
                int e = permutation[i];
                w.Write("  ");
                w.Write(E(graph, e));
                w.WriteLine($" [label={i.ToString(F)}]");
            }

            w.WriteLine("}");
        }
Example #6
0
        private static void Main()
        {
            IndexedIncidenceGraph.Builder builder = new(0, 31);

            using (TextReader textReader = IndexedGraphs.GetTextReader("09"))
            {
                IEnumerable <Endpoints> edges = IndexedEdgeListParser.ParseEdges(textReader);
                foreach (Endpoints edge in edges)
                {
                    builder.Add(edge.Tail, edge.Head);
                }
            }

            IndexedIncidenceGraph graph = builder.ToGraph();

            Console.Write($"{nameof(graph.VertexCount)}: {graph.VertexCount.ToString(F)}");
            Console.WriteLine($", {nameof(graph.EdgeCount)}: {graph.EdgeCount.ToString(F)}");

            TextWriter w = Console.Out;

            EagerBfs <IndexedIncidenceGraph, int, int, ArraySegment <int> .Enumerator> bfs = default;

            w.WriteLine($"digraph \"{bfs.GetType().Name}\" {{");
            w.WriteLine("  node [shape=circle style=dashed fontname=\"Times-Italic\"]");

            // Enumerate vertices.
            for (int v = 0; v < graph.VertexCount; ++v)
            {
                w.Write(v == 0 ? "  " : " ");
                w.Write(V(v));
            }

            w.WriteLine();

            IndexEnumerator sources = new(2);

            byte[] backingStore = ArrayPool <byte> .Shared.Rent(graph.VertexCount);

            Array.Clear(backingStore, 0, backingStore.Length);
            IndexedColorDictionary colorMap      = new(backingStore);
            HashSet <int>          examinedEdges = new(graph.EdgeCount);
            BfsHandler <IndexedIncidenceGraph, int, int> handler = CreateHandler(w, examinedEdges);

            bfs.Traverse(graph, sources, colorMap, handler);
            ArrayPool <byte> .Shared.Return(backingStore);

            // Enumerate sources.
            w.WriteLine();
            sources.Reset();
            while (sources.MoveNext())
            {
                int v = sources.Current;
                w.WriteLine($"  {V(v)} [style=filled]");
            }

            // Enumerate rest of edges.
            w.WriteLine();
            for (int v = 0; v < graph.VertexCount; ++v)
            {
                ArraySegment <int> .Enumerator outEdges = graph.EnumerateOutEdges(v);
                while (outEdges.MoveNext())
                {
                    int e = outEdges.Current;
                    if (examinedEdges.Contains(e))
                    {
                        continue;
                    }

                    w.WriteLine($"  {E(graph, e)} [label={e} style=dotted]");
                }
            }

            w.WriteLine("}");
        }