当前位置: 首页>>代码示例>>C#>>正文


C# BitSet.First方法代码示例

本文整理汇总了C#中BitSet.First方法的典型用法代码示例。如果您正苦于以下问题:C# BitSet.First方法的具体用法?C# BitSet.First怎么用?C# BitSet.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitSet的用法示例。


在下文中一共展示了BitSet.First方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connected

        // Uses depth-first search to check if the graph induced by the subgraph given as a parameter is connected
        // In other words, we retreive all edges from the original graph and check the subgraph for connectedness
        public static bool Connected(Datastructures.Graph graph, BitSet subgraph)
        {
            // Vertices that are visited
            Set<int> visited = new Set<int>();

            // Stack of vertices yet to visit
            Stack<int> stack = new Stack<int>();

            // Initial vertex
            int s = subgraph.First();
            stack.Push(s);

            // Continue while there are vertices on the stack
            while (stack.Count > 0)
            {
                int v = stack.Pop();

                // If we have not encountered this vertex before, then we check for all neighbors if they are part of the subgraph
                // If a neighbor is part of the subgraph it means that we have to push it on the stack to explore it at a later stage
                if (!visited.Contains(v))
                {
                    visited.Add(v);

                    foreach (int w in graph.OpenNeighborhood(v))
                        if (subgraph.Contains(w))
                            stack.Push(w);
                }
            }

            // If we visited an equal number of vertices as there are vertices in the subgraph then the subgraph is connected
            return visited.Count == subgraph.Count;
        }
开发者ID:Miloan,项目名称:BooleanWidth,代码行数:34,代码来源:DepthFirstSearch.cs

示例2: ConstructTree

        // Constructs the actual width values
        private static void ConstructTree(Datastructures.Graph graph, BitSet A)
        {
            long min = A.Count == 1 ? 0 : long.MaxValue;
            int n = graph.Size;
            int v = -1;     // v is the vertex that if we remove it from A, we have the smallest number of neighbors
            BitSet optimal = new BitSet(0, n);

            Set<BitSet> subsets = new Set<BitSet>(new BitSet(0, n));
            foreach (int a in A)
            {
                Set<BitSet> newSubsets = new Set<BitSet>();
                foreach (BitSet j in subsets)
                {
                    BitSet subset = j + a;
                    BitSet inverse = A - subset;

                    if (subset.Equals(A)) continue; // only consider strict subsets

                    if (!_width.ContainsKey(subset))
                        ConstructTree(graph, subset);

                    if (!_width.ContainsKey(inverse))
                        ConstructTree(graph, inverse);

                    newSubsets.Add(subset); // add this for the next iteration

                    long max = Math.Max(_width[subset], _width[inverse]); // either S or A\S will be the bottleneck

                    if (max < min)
                    {
                        min = max;
                        optimal = subset; // it doesn't matter if we take j + a or A - (j + a), since when retrieving the tree we split them anyway

                        if (inverse.Count == 1)
                            v = inverse.First();
                    }
                }

                subsets.AddRange(newSubsets);
            }

            v = v == -1 ? A.First() : v;
            BitSet nv = graph.OpenNeighborhood(v) * (graph.Vertices - (A - v));
            Set<BitSet> un = new Set<BitSet>();
            foreach (BitSet _base in _neighborhoods[A - v])
            {
                un.Add(_base - v);          // previous neighbor without v is a possible new neighborhood
                un.Add((_base - v) + nv);   // previous neighbor without v, unioned with the neighborhood of v is a possible new neighborhood
            }
            _neighborhoods[A] = un;
            _cuts[A] = _neighborhoods[A].Count;

            _width[A] = Math.Max(min, _cuts[A]);  // Actual possible width to get to this cut
            _optimalChild[A] = optimal;
        }
开发者ID:Miloan,项目名称:BooleanWidth,代码行数:56,代码来源:ExactDecomposer.cs

示例3: _recursionSimple

 private void _recursionSimple(TextWriter writer, BitSet node)
 {
     if (node.Count == 1)
     {
         writer.WriteLine(node.First());
     }
     else
     {
         writer.WriteLine("\"\"");
         writer.WriteLine("-> {");
         _recursionSimple(writer, LeftChild[node]);
         writer.WriteLine(",");
         _recursionSimple(writer, RightChild[node]);
         writer.WriteLine("}");
     }
 }
开发者ID:Miloan,项目名称:BooleanWidth,代码行数:16,代码来源:Tree.cs


注:本文中的BitSet.First方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。