コード例 #1
0
ファイル: Matching.cs プロジェクト: roddickchen/NCDK
        /// <summary>
        /// Attempt to augment the matching such that it is perfect over the subset
        /// of vertices in the provided graph.
        /// </summary>
        /// <param name="graph">adjacency list representation of graph</param>
        /// <param name="subset">subset of vertices</param>
        /// <returns>the matching was perfect</returns>
        /// <exception cref="ArgumentException">the graph was a different size to the matching capacity</exception>
        public bool Perfect(int[][] graph, BitArray subset)
        {
            if (graph.Length != match.Length || BitArrays.Cardinality(subset) > graph.Length)
            {
                throw new ArgumentException("graph and matching had different capacity");
            }

            // and odd set can never provide a perfect matching
            if ((BitArrays.Cardinality(subset) & 0x1) == 0x1)
            {
                return(false);
            }

            // arbitrary matching was perfect
            if (ArbitaryMatching(graph, subset))
            {
                return(true);
            }

            EdmondsMaximumMatching.Maxamise(this, graph, subset);

            // the matching is imperfect if any vertex was
            for (int v = BitArrays.NextSetBit(subset, 0); v >= 0; v = BitArrays.NextSetBit(subset, v + 1))
            {
                if (Unmatched(v))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        private Matching CreateMatching(IAtomContainer container, params int[] xs)
        {
            BitArray subset = new BitArray(container.Atoms.Count);

            if (xs.Length == 0)
            {
                BitArrays.Flip(subset, 0, container.Atoms.Count);
            }
            else
            {
                foreach (var x in xs)
                {
                    subset.Set(x, true);
                }
            }
            Matching m = Matching.WithCapacity(container.Atoms.Count);

            return(EdmondsMaximumMatching.Maxamise(m, GraphUtil.ToAdjList(container), subset));
        }