Skip to content

Commit

Permalink
solved probrem about deepcopy heavywatal#22
Browse files Browse the repository at this point in the history
  • Loading branch information
hamazaki1990 committed May 28, 2017
1 parent 98965aa commit 90e6f39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions hamazaki1990/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Individual:
mutationrate = 1
mutationrate = 0.1

def __init__(self, n, f=1.0):
self._id = n
Expand Down Expand Up @@ -49,12 +49,12 @@ def main():
print(ind2.get_id())
print(ind2.get_fitness())

ind3 = Individual(0, 1.0)
ind4 = Individual(1, 1.0)
ind3 = Individual(0)
ind4 = Individual(1)
pop = [ind3, ind4]
print([x.get_genotype() for x in pop])
[x.acquire_mutation() for x in pop]
print([x.get_genotype() for x in pop])
pop1 = [x.acquire_mutation() for x in pop]
print([x.get_genotype() for x in pop1])
[x.acquire_mutation() for x in pop]
print([x.get_genotype() for x in pop])

Expand Down
6 changes: 3 additions & 3 deletions hamazaki1990/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def next_genwf(self):
parent_inds = roulettechoice(self._inds, cumsum_fitness)
next_inds = parent_inds.acquire_mutation()
next_generation.append(next_inds)
return next_generation
self._inds = next_generation

def next_genmo(self):
fitness = [x.get_fitness() for x in self._inds]
size = len(self._inds)
cumsum_fitness = [sum(fitness[:i]) for i in range(1, size + 1)]
i_dying = random.randrange(size)
next_inds = roulettechoice(self._inds, cumsum_fitness)
next_inds.acquire_mutation()
parent_inds = roulettechoice(self._inds, cumsum_fitness)
next_inds = parent_inds.acquire_mutation()
self._inds[i_dying] = next_inds

def list_mutation(self):
Expand Down

0 comments on commit 90e6f39

Please sign in to comment.