/// <summary> /// Check if it is possible to assign electrons to the subgraph (specified by /// the set bits in of <paramref name="bs"/>). Each connected subset is counted up and /// checked for odd cardinality. /// </summary> /// <param name="g"> graph</param> /// <param name="bs">binary set indicated vertices for the subgraph</param> /// <returns>there is an odd cardinality subgraph</returns> private static bool ContainsOddCardinalitySubgraph(Graph g, BitArray bs) { // mark visited those which are not in any subgraph bool[] visited = new bool[g.Order]; for (int i = BitArrays.NextClearBit(bs, 0); i < g.Order; i = BitArrays.NextClearBit(bs, i + 1)) { visited[i] = true; } // from each unvisited vertices visit the connected vertices and count // how many there are in this component. if there is an odd number there // is no assignment of double bonds possible for (int i = BitArrays.NextSetBit(bs, 0); i >= 0; i = BitArrays.NextSetBit(bs, i + 1)) { if (!visited[i] && IsOdd(Visit(g, i, 0, visited))) { return(true); } } return(false); }