示例#1
0
// Returns the categories of all nodes.  The return value is a vector such
// that the i-th entry is the category of the i-th node.
std::vector<int> CommDetection::Communities() {
    std::vector<int> communities(num_nodes_, -1);
    for (int i = 0; i < labels_.size(); ++i) {
        std::vector<int>& curr_labels = labels_[i];
        for (int node : curr_labels) {
            communities[node] = i;
        }
    }

    for (int comm : communities) {
        if (comm == -1) {
            std::logic_error("Not all nodes assigned communities.");
        }
    }

    return communities;
}
NetworKit::Cover NetworKit::CoverReader::read(std::string path, NetworKit::Graph &G)
{
	std::ifstream file;
	file.open(path);
	if (!file.good()) {
		throw std::runtime_error("unable to read from file");
	}
	Cover communities(G.upperNodeIdBound());
	std::string line;
	count i = 0;
	node current;

	while (std::getline(file, line)) {
		if (line.substr(0, 1) != "#") {
			communities.setUpperBound(i+1);
			std::stringstream linestream(line);
			while (linestream >> current) {
				communities.addToSubset(i, current);
			}
			++i;
		}
	}