Skip to content

Commit

Permalink
approaching heavywatal#22
Browse files Browse the repository at this point in the history
  • Loading branch information
hamazaki1990 committed May 24, 2017
1 parent de6f305 commit 03ff7d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
4 changes: 1 addition & 3 deletions hamazaki1990/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
30 changes: 15 additions & 15 deletions hamazaki1990/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 03ff7d3

Please sign in to comment.