Example #1
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 #2
0
        internal void EnumerateVertices(GraphParameter <Graph> p)
        {
            SimpleIncidenceGraph graph = p.Graph;

            // Arrange

            int source = graph.VertexCount >> 1;

            byte[] setBackingStore = ArrayPool <byte> .Shared.Rent(Math.Max(graph.VertexCount, source + 1));

            Array.Clear(setBackingStore, 0, setBackingStore.Length);
            IndexedSet exploredSet = new(setBackingStore);

            // Act

            IEnumerator <int> basicSteps      = Dfs.EnumerateVertices(graph, source, graph.VertexCount) !;
            IEnumerator <int> enumerableSteps = EnumerableDfs.EnumerateVertices(graph, source, exploredSet) !;

            // Assert

            while (true)
            {
                bool expectedHasCurrent = enumerableSteps.MoveNext();
                bool actualHasCurrent   = basicSteps.MoveNext();

                Assert.Equal(expectedHasCurrent, actualHasCurrent);

                if (!expectedHasCurrent || !actualHasCurrent)
                {
                    break;
                }

                int expected = enumerableSteps.Current;
                int actual   = basicSteps.Current;

                if (expected != actual)
                {
                    Assert.Equal(expected, actual);
                    break;
                }
            }
        }
 internal void EnumerateVertices_MultipleSource(GraphParameter <Graph> p)
 {
     EnumerateVerticesCore(p.Graph, true);
 }
 internal void EnumerateVertices_SingleSource(GraphParameter <Graph> p)
 {
     EnumerateVerticesCore(p.Graph, false);
 }