-
Notifications
You must be signed in to change notification settings - Fork 0
/
chromosome.py
25 lines (22 loc) · 866 Bytes
/
chromosome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Chromosome:
def __init__(self,data,fitnessfunction):
#Data is an array of strings
self.data = data
self.calculate_integer_values()
self.fitness_function = fitnessfunction
self.result = 0
def give_group_of_gens(self,index):
return self.data[index]
def give_group_off_gens_excluding(self, index):
return [self.data[:index],self.data[index:]]
def calculate_integer_values(self):
self.integerValues = []
for string_value in self.data:
self.integerValues.append(int(string_value,2))
# print(self.integerValues)
def calculate_value(self):
self.result = self.fitness_function(self.integerValues)
# print(self.result)
def mutate_group_of_gens(self,gens,index):
self.data[index] = gens
self.calculate_integer_values()