Ejemplo n.º 1
0
//#define DEBUG
void SymList::compute_subgroup()
{
    Matrix2D<DOUBLE> I(4, 4);
    I.initIdentity();
    Matrix2D<DOUBLE> L1(4, 4), R1(4, 4), L2(4, 4), R2(4, 4), newL(4, 4), newR(4, 4);
    Matrix2D<int>    tried(true_symNo, true_symNo);
    int i, j;
    int new_chain_length;
    while (found_not_tried(tried, i, j, true_symNo))
    {
        tried(i, j) = 1;

        get_matrices(i, L1, R1);
        get_matrices(j, L2, R2);
        newL = L1 * L2;
        newR = R1 * R2;
        new_chain_length = __chain_length(i) + __chain_length(j);
        Matrix2D<DOUBLE> newR3 = newR;
        newR3.resize(3,3);
        if (newL.isIdentity() && newR3.isIdentity()) continue;

        // Try to find it in current ones
        bool found;
        found = false;
        for (int l = 0; l < SymsNo(); l++)
        {
        	get_matrices(l, L1, R1);
            if (newL.equal(L1) && newR.equal(R1))
            {
                found = true;
                break;
            }
        }

        if (!found)
        {
//#define DEBUG
#ifdef DEBUG
           std::cout << "Matrix size " << tried.Xdim() << " "
            << "trying " << i << " " << j << " "
            << "chain length=" << new_chain_length << std::endl;
            std::cout << "Result R Sh\n" << newR;
#endif
#undef DEBUG
            newR.setSmallValuesToZero();
            newL.setSmallValuesToZero();
            add_matrices(newL, newR, new_chain_length);
            tried.resize(MAT_YSIZE(tried) + 1, MAT_XSIZE(tried) + 1);
        }
    }
}
Ejemplo n.º 2
0
// TODO: Refactor this function
float Apportionment::checkFitness(Genome * genome) {
	std::vector<float> apportionedFitnesses;
	std::vector<bool> tried(this->upperNode->populationSize(), false);
	unsigned int triedOn = 0;

	for (unsigned int i = 0; i < this->upperNode->populationSize(); i++) {
		Genome * upper = this->upperNode->getIndex(i);
		if (this->upperGenomeUsesComponent(upper, genome)) {
			this->evaluatePair(
				upper,
				genome,
				this->upperNode->getFitnessAtIndex(i),
				apportionedFitnesses
			);
			triedOn++;
			tried[i] = true;
		}
	}

	std::vector<unsigned int> untriedIndices;
	for (unsigned int i = 0; i < tried.size(); i++)
		if (!tried[i]) untriedIndices.push_back(i);

	unsigned int realTryOns = std::min(
		this->upperNode->populationSize(),
		this->tryOns
	);

	unsigned int index;
	while (triedOn < realTryOns) {
		index = HierRNG::index(untriedIndices.size() - 1);

		Genome * provider = this->upperNode
			->getIndex(untriedIndices[index])
			->replaceComponent(genome);
		this->evaluatePair(
			provider,
			genome,
			this->upperNode->evaluateFitness(provider),
			apportionedFitnesses
		);
		delete(provider);
		untriedIndices.erase(untriedIndices.begin() + index);
		triedOn++;
	}

	return this->aggregateFitnesses(apportionedFitnesses);
}