コード例 #1
0
        private static void VerifySinkConnector <TVertex, TEdge>(
            [NotNull] IVertexListGraph <TVertex, TEdge> graph,
            // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
            [NotNull] MultiSourceSinkGraphAugmentorAlgorithm <TVertex, TEdge> augmentor,
            [NotNull, ItemNotNull] TVertex[] noOutEdgesVertices)
            where TEdge : IEdge <TVertex>
        {
            foreach (TVertex vertex in noOutEdgesVertices)
            {
                Assert.IsTrue(graph.ContainsEdge(vertex, augmentor.SuperSink));
            }

            foreach (TVertex vertex in graph.Vertices.Except(noOutEdgesVertices))
            {
                if (vertex.Equals(augmentor.SuperSource))
                {
                    continue;
                }
                if (vertex.Equals(augmentor.SuperSink))
                {
                    continue;
                }
                Assert.IsFalse(graph.ContainsEdge(vertex, augmentor.SuperSink));
            }
        }
コード例 #2
0
        private static void RunAugmentationAndCheck(
            [NotNull] IMutableBidirectionalGraph <string, Edge <string> > graph)
        {
            int vertexCount = graph.VertexCount;
            int edgeCount   = graph.EdgeCount;
            int vertexId    = graph.VertexCount + 1;

            string[] noInEdgesVertices  = graph.Vertices.Where(graph.IsInEdgesEmpty).ToArray();
            string[] noOutEdgesVertices = graph.Vertices.Where(graph.IsOutEdgesEmpty).ToArray();

            using (var augmentor = new MultiSourceSinkGraphAugmentorAlgorithm <string, Edge <string> >(
                       graph,
                       () => (vertexId++).ToString(),
                       (s, t) => new Edge <string>(s, t)))
            {
                bool added = false;
                augmentor.EdgeAdded += edge => { added = true; };

                augmentor.Compute();
                Assert.IsTrue(added);
                VerifyVertexCount(graph, augmentor, vertexCount);
                VerifySourceConnector(graph, augmentor, noInEdgesVertices);
                VerifySinkConnector(graph, augmentor, noOutEdgesVertices);
            }

            Assert.AreEqual(graph.VertexCount, vertexCount);
            Assert.AreEqual(graph.EdgeCount, edgeCount);
        }
コード例 #3
0
        public void Constructor()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();
            VertexFactory <int>            vertexFactory = () => 1;
            EdgeFactory <int, Edge <int> > edgeFactory   = (source, target) => new Edge <int>(source, target);

            var algorithm = new MultiSourceSinkGraphAugmentorAlgorithm <int, Edge <int> >(graph, vertexFactory, edgeFactory);

            AssertAlgorithmProperties(algorithm, graph, vertexFactory, edgeFactory);

            algorithm = new MultiSourceSinkGraphAugmentorAlgorithm <int, Edge <int> >(null, graph, vertexFactory, edgeFactory);
            AssertAlgorithmProperties(algorithm, graph, vertexFactory, edgeFactory);

            #region Local function

            void AssertAlgorithmProperties <TVertex, TEdge>(
                MultiSourceSinkGraphAugmentorAlgorithm <TVertex, TEdge> algo,
                IMutableBidirectionalGraph <TVertex, TEdge> g,
                VertexFactory <int> vFactory,
                EdgeFactory <int, Edge <int> > eFactory)
                where TEdge : IEdge <TVertex>
            {
                AssertAlgorithmState(algo, g);
                Assert.IsFalse(algo.Augmented);
                CollectionAssert.IsEmpty(algo.AugmentedEdges);
                Assert.AreSame(vFactory, algo.VertexFactory);
                Assert.AreSame(eFactory, algo.EdgeFactory);
                Assert.AreEqual(default(TVertex), algo.SuperSource);
                Assert.AreEqual(default(TVertex), algo.SuperSink);
            }

            #endregion
        }
コード例 #4
0
        public void RunAugmentation_Throws()
        {
            var graph    = new BidirectionalGraph <int, Edge <int> >();
            int vertexID = 0;
            VertexFactory <int>            vertexFactory = () => ++ vertexID;
            EdgeFactory <int, Edge <int> > edgeFactory   = (source, target) => new Edge <int>(source, target);
            var algorithm = new MultiSourceSinkGraphAugmentorAlgorithm <int, Edge <int> >(graph, vertexFactory, edgeFactory);

            RunAugmentation_Throws_Test(algorithm);
        }
コード例 #5
0
        public void CreateAndSetSuperSink()
        {
            var graph    = new BidirectionalGraph <int, Edge <int> >();
            int vertexID = 0;
            VertexFactory <int>            vertexFactory = () => ++ vertexID;
            EdgeFactory <int, Edge <int> > edgeFactory   = (source, target) => new Edge <int>(source, target);
            var algorithm = new MultiSourceSinkGraphAugmentorAlgorithm <int, Edge <int> >(graph, vertexFactory, edgeFactory);

            CreateAndSetSuperSink_Test(algorithm);
        }
コード例 #6
0
 private static void VerifyVertexCount <TVertex, TEdge>(
     [NotNull] IVertexSet <TVertex> graph,
     // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
     [NotNull] MultiSourceSinkGraphAugmentorAlgorithm <TVertex, TEdge> augmentor,
     int vertexCount)
     where TEdge : IEdge <TVertex>
 {
     Assert.AreEqual(vertexCount + 2 /* Source + Sink */, graph.VertexCount);
     Assert.IsTrue(graph.ContainsVertex(augmentor.SuperSource));
     Assert.IsTrue(graph.ContainsVertex(augmentor.SuperSink));
 }