public void UnBalance_Throws()
        {
            var graph = new BidirectionalGraph <int, Edge <int> >();

            graph.AddVertexRange(new[] { 1, 2 });
            VertexFactory <int>            vertexFactory = () => 1;
            EdgeFactory <int, Edge <int> > edgeFactory   = (source, target) => new Edge <int>(source, target);

            var algorithm = new GraphBalancerAlgorithm <int, Edge <int> >(graph, 1, 2, vertexFactory, edgeFactory);

            Assert.Throws <InvalidOperationException>(() => algorithm.UnBalance());
        }
        public void UnBalance()
        {
            var edge12 = new Edge <int>(1, 2);
            var edge13 = new Edge <int>(1, 3);
            var edge23 = new Edge <int>(2, 3);
            var edge32 = new Edge <int>(3, 2);
            var edge34 = new Edge <int>(3, 4);
            var edge56 = new Edge <int>(5, 6);

            var graph = new BidirectionalGraph <int, Edge <int> >();

            graph.AddVerticesAndEdgeRange(new[]
            {
                edge12, edge13, edge23, edge32, edge34, edge56
            });
            int vertexID = 6;
            VertexFactory <int>            vertexFactory = () => vertexID++;
            EdgeFactory <int, Edge <int> > edgeFactory   = (source, target) => new Edge <int>(source, target);

            var algorithm = new GraphBalancerAlgorithm <int, Edge <int> >(graph, 1, 3, vertexFactory, edgeFactory);

            algorithm.Balance();

            Assert.IsTrue(algorithm.Balanced);

            algorithm.UnBalance();

            Assert.IsFalse(algorithm.Balanced);
            Assert.AreEqual(1, algorithm.Source);
            Assert.AreEqual(3, algorithm.Sink);
            CollectionAssert.IsEmpty(algorithm.SurplusVertices);
            CollectionAssert.IsEmpty(algorithm.SurplusEdges);
            CollectionAssert.IsEmpty(algorithm.DeficientVertices);
            CollectionAssert.IsEmpty(algorithm.DeficientEdges);
            Assert.AreEqual(default(int), algorithm.BalancingSource);
            Assert.AreEqual(default(Edge <int>), algorithm.BalancingSourceEdge);
            Assert.AreEqual(default(int), algorithm.BalancingSink);
            Assert.AreEqual(default(Edge <int>), algorithm.BalancingSinkEdge);
        }
Beispiel #3
0
 public void UnBalanceBeforeBalancing()
 {
     g    = GraphFactory.UnBalancedFlow();
     algo = new GraphBalancerAlgorithm(g, Traversal.FirstVertex(g), Traversal.FirstVertex(g));
     algo.UnBalance();
 }