diff --git a/hamazaki1990/individual.py b/hamazaki1990/individual.py index 36d06f6..f83aa71 100644 --- a/hamazaki1990/individual.py +++ b/hamazaki1990/individual.py @@ -20,14 +20,12 @@ def get_genotype(self): def acquire_mutation(self): r = random.random() next_genotype = self._genotype - if self._mutationrate > r: + if r < self._mutationrate: next_genotype.append(random.random()) self._genotype = next_genotype def __repr__(self): return str(self._id) - return str(self._fitness) - return str(self._genotype) def main(): diff --git a/hamazaki1990/population.py b/hamazaki1990/population.py index b6bc41d..528c458 100644 --- a/hamazaki1990/population.py +++ b/hamazaki1990/population.py @@ -49,19 +49,19 @@ def acquire_mutations(self): genotypes = [x.get_genotype() for x in self._inds] return genotypes - def get_mutationlist(self): + def list_mutation(self): genotypes = [x.get_genotype() for x in self._inds] - mutation_sites = [] - for x in range(len(genotypes)): - mutation_sites.extend(genotypes[x]) - mutation_sites = sorted(mutation_sites) - mutation_list = [[0 for x in range(len(mutation_sites))] for y in range(len(self._inds))] - for x in range(len(self._inds)): - for y in range(len(genotypes[x])): - i = mutation_sites.index(genotypes[x][y]) - if i != "ValueError": - mutation_list[x][i] += 1 - print(mutation_list) + m_sites = [] + for x in genotypes: + m_sites.extend(x) + m_sites = sorted(m_sites) + m_list = [[0 for x in range(len(m_sites))] for y in range(len(self._inds))] + for i in range(len(self._inds)): + for j in range(len(genotypes[i])): + k = m_sites.index(genotypes[i][j]) + if k != "ValueError": + m_list[i][k] += 1 + print(m_list) def is_not_fixed(self): for x in range(1, len(self._inds)): @@ -126,11 +126,11 @@ def main(): print(p2_2.get_fitnesses()) p3_1 = Population(10, 0, 0, 0.8) - p3_1.get_mutationlist() + p3_1.list_mutation() print(p3_1.acquire_mutations()) - p3_1.get_mutationlist() + p3_1.list_mutation() print(p3_1.acquire_mutations()) - p3_1.get_mutationlist() + p3_1.list_mutation() if __name__ == '__main__':