/*
 * PartitionReader.cpp
 *
 *  Created on: 15.02.2013
 *      Author: Christian Staudt (christian.staudt@kit.edu)
 */

#include "PartitionReader.h"

namespace NetworKit {

Partition PartitionReader::read(std::string path) {

	std::ifstream file(path);

	// check if file readable
	if (!file) {
		throw std::runtime_error("invalid clustering file");
	}


	std::vector<index> temp;

	// push all cluster ids into vector in order of appearance
	std::string line;
	while(std::getline(file, line)) {
		index c = std::atoi(line.c_str());
		temp.push_back(c);
	}

	count n = temp.size();
	Partition zeta(n);

	#pragma omp parallel for
	for (node u = 0; u < n; ++u) {
		zeta[u] = temp[u];
	}

	return zeta;
}

} /* namespace NetworKit */

/*
 * PartitionReader.cpp
 *
 *  Created on: 15.02.2013
 *      Author: Christian Staudt (christian.staudt@kit.edu)
 */

#include "PartitionReader.h"

namespace NetworKit {

Partition PartitionReader::read(std::string path) {

	std::ifstream file(path);

	// check if file readable
	if (!file) {
		throw std::runtime_error("invalid clustering file");
	}


	Partition zeta(0);

	std::string line;
	index omega = 0;
	while(std::getline(file, line)) {
		index c = std::atoi(line.c_str());
		// extend the partition by one entry and store the cluster id
		zeta[zeta.extend()] = c;
		omega = std::max(c, omega);
	}

	zeta.setUpperBound(omega+1);

	return zeta;
}

} /* namespace NetworKit */

Simplify and fix the partition reader
Simplify and fix the partition reader

This fixes the partition reader to correctly set the upper bound of the
partition ids. Furthermore the partition reader is simplified to create
the partition directly in the partition instance instead of a separate
vector as the partition instance also simply expands a std::vector when
new nodes are added.
