Пример #1
0
        private MaximumMatching(Graph graph, Matching matching, int nMatched, IntSet subset)
        {
            this.graph    = graph;
            this.matching = matching;
            this.subset   = subset;

            this.even = new int[graph.Order];
            this.odd  = new int[graph.Order];

            this.queue = new FixedSizeQueue(graph.Order);
            this.uf    = new UnionFind(graph.Order);

            // tmp storage of paths in the algorithm
            path       = new int[graph.Order];
            vAncestors = new BitArray(graph.Order);
            wAncestors = new BitArray(graph.Order);

            // continuously augment while we find new paths, each
            // path increases the matching cardinality by 2
            while (Augment())
            {
                nMatched += 2;
            }

            this.nMatched = nMatched;
        }
Пример #2
0
        public void Find()
        {
            UnionFind uf = new UnionFind(100);

            uf.Union(1, 5);
            uf.Union(7, 9);
            uf.Union(10, 11);
            uf.Union(15, 1);
            uf.Union(15, 50);
            Assert.AreEqual(uf.Find(1), 50);
            Assert.AreEqual(uf.Find(5), 50);
            Assert.AreEqual(uf.Find(7), 7);
            Assert.AreEqual(uf.Find(8), 8);
            Assert.AreEqual(uf.Find(10), 10);
            Assert.AreEqual(uf.Find(11), 10);
            Assert.AreEqual(uf.Find(15), 50);
            Assert.AreEqual(uf.Find(50), 50);
        }
Пример #3
0
        public void Connected()
        {
            UnionFind uf = new UnionFind(100);

            uf.Union(1, 5);
            uf.Union(7, 9);
            uf.Union(7, 5);
            uf.Union(10, 11);
            uf.Union(11, 50);
            uf.Union(15, 1);
            uf.Union(15, 50);
            Assert.IsTrue(uf.Connected(1, 5));
            Assert.IsTrue(uf.Connected(1, 7));
            Assert.IsTrue(uf.Connected(1, 9));
            Assert.IsTrue(uf.Connected(1, 10));
            Assert.IsTrue(uf.Connected(1, 11));
            Assert.IsTrue(uf.Connected(1, 15));
            Assert.IsTrue(uf.Connected(1, 50));
        }