void Graph::_calculateSSSRByCycleBasis (CycleBasis &basis) { _calculateSSSRInit(); for (int i = 0; i < basis.getCyclesCount(); i++) { const Array<int> &cycle = basis.getCycle(i); List<int> &vertices = _sssr_vertices.push(*_sssr_pool); List<int> &edges = _sssr_edges.push(*_sssr_pool); _calculateSSSRAddEdgesAndVertices(cycle, edges, vertices); for (int j = vertices.begin(); j != vertices.end(); j = vertices.next(j)) { int idx = vertices[j]; if (_v_smallest_ring_size[idx] == -1 || _v_smallest_ring_size[idx] > cycle.size()) _v_smallest_ring_size[idx] = cycle.size(); _v_sssr_count[idx]++; } } for (int i = 0; i < _v_smallest_ring_size.size(); i++) if (_v_smallest_ring_size[i] == -1) _v_smallest_ring_size[i] = 0; _sssr_valid = true; }
void Graph::_calculateSSSR () { CycleBasis basis; int i, j; basis.create(*this); _v_smallest_ring_size.clear_resize(vertexEnd()); _v_sssr_count.clear_resize(vertexEnd()); _v_smallest_ring_size.fffill(); _v_sssr_count.zerofill(); if (_sssr_pool == 0) _sssr_pool = new Pool<List<int>::Elem>(); _sssr_vertices.clear(); _sssr_edges.clear(); for (i = 0; i < basis.getCyclesCount(); i++) { const Array<int> &cycle = basis.getCycle(i); List<int> &vertices = _sssr_vertices.push(*_sssr_pool); List<int> &edges = _sssr_edges.push(*_sssr_pool); int prev_beg = -1; int prev_end = -1; for (j = 0; j < cycle.size(); j++) { const Edge &edge = getEdge(cycle[j]); edges.add(cycle[j]); if (j != cycle.size() - 1) { if (edge.beg != prev_beg && edge.beg != prev_end) vertices.add(edge.beg); if (edge.end != prev_beg && edge.end != prev_end) vertices.add(edge.end); } prev_beg = edge.beg; prev_end = edge.end; } for (j = vertices.begin(); j != vertices.end(); j = vertices.next(j)) { int idx = vertices[j]; if (_v_smallest_ring_size[idx] == -1 || _v_smallest_ring_size[idx] > cycle.size()) _v_smallest_ring_size[idx] = cycle.size(); _v_sssr_count[idx]++; } } for (i = 0; i < _v_smallest_ring_size.size(); i++) if (_v_smallest_ring_size[i] == -1) _v_smallest_ring_size[i] = 0; _sssr_valid = true; }