Exemplo n.º 1
0
bool Population::init(const IndividualContainer &origin, unsigned int popSize) {

	if (!origin.areEvaluated()) {
		std::cout << "Trying to initialize population of n best Robots from "
				"IndividualContainer which is not evaluated!" << std::endl;
		return false;
	}

	for (unsigned int i = 0; i < origin.size(); i++) {
		this->push_back(origin[i]);
	}

	this->sort();

	// idea was to call this->resize(popSize);, but that requires a default
	// constructor to be present for RobotRepresentation, which is not the case
	// on purpose
	while (this->size() > popSize) {
		this->pop_back();
	}

	this->evaluated_ = true;

	return true;
}