tsp_individual_multi::DNA tsp_individual_multi::translateToDnaPhenotypicOrdinal(const DNA trait){ DNA ordinal; DNA tmp; for(int i=0;i<trait.size();i++){ tmp.push_back(i); } ordinal.resize(trait.size()); for(int i=0;i<trait.size();i++){ ordinal[i] = tmp[trait[i]]; tmp.erase(tmp.begin() + trait[i]); } return ordinal; }
tsp_individual_multi::DNA tsp_individual_multi::translateToDnaPhenotypicTrait(const DNA ordinal){ DNA trait; DNA tmp; for(int i=0;i<ordinal.size();i++){ tmp.push_back(i); } for(int i=0;i<ordinal.size();i++){ for(int j=0;j<tmp.size();j++){ if(ordinal[i] == tmp[j]){ trait.push_back(j); tmp.erase(tmp.begin() + j); break; } } } return trait; }
vector<DNA<false>> FrequentWords(const DNA<IsCyclic>& dnaString, int k) { //Initialize dictionary unordered_map<DNA<false>, int> counts{ }; size_t n{ dnaString.size() }; //Fill dictionary and count kmer frequencies int maxCount{ 1 }; for (size_t i = 0; i < n - k + 1; i++) { DNA<false> part{ dnaString.slice(i, k) }; auto it = counts.find(part); if (it == end(counts)) { counts[part] = 1; } else { it->second++; if (maxCount < it->second) maxCount = it->second; }; }; //Extract most frequent words vector<DNA<false>> most_frequent_words{ }; for (auto& p : counts) if (p.second == maxCount) most_frequent_words.push_back(p.first); return most_frequent_words; };