double Genome::GetGeneticalDistanceFrom(const Genome& other) const { double totalWeightDifference = 0.0; size_t numberOfOverlapingGenes = 0; size_t sizeOfSmallerGenome = min(this->GetGeneCount(), other.GetGeneCount()); auto IsHistoricalMarkingSameAt = [&](size_t i) { return this->GetGeneAt(i).historicalMarking == other[i].historicalMarking; }; for (size_t i = 0; i < sizeOfSmallerGenome && IsHistoricalMarkingSameAt(i); ++i) { totalWeightDifference += (double)abs(this->GetGeneAt(i).weight - other[i].weight); ++numberOfOverlapingGenes; } auto numberOfDisjointGenes = this->GetGeneCount() + other.GetGeneCount() - (size_t)2 * numberOfOverlapingGenes; auto sizeOfBiggerGenome = max(this->GetGeneCount(), other.GetGeneCount()); // TODO jnf: Think how we'll handle the next line auto disjointGenesInfluence = (double)numberOfDisjointGenes /* / (double)sizeOfBiggerGenome*/; auto averageWeightDifference = totalWeightDifference / (double)numberOfOverlapingGenes; disjointGenesInfluence *= (double)parameters.advanced.speciation.importanceOfDisjointGenes; averageWeightDifference *= (double)parameters.advanced.speciation.importanceOfAverageWeightDifference; return disjointGenesInfluence + averageWeightDifference; }