本文整理汇总了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;
}
示例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;
}
示例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("}");
}
}