def kill(population, mi, d): overall = 0 temp_af = [] maxx = 0.0 max_i = 0 for i in range(len(population)): # print("licze overall") x = dekoder.decode(population[i])[0] y = dekoder.decode(population[i])[1] a = dekoder.decode(population[i])[2] temp_af.append(math.exp(afunction.J(x, y, a, d)) ** 2) overall += temp_af[i] if maxx != max(maxx, temp_af[i]): maxx = max(maxx, temp_af[i]) max_i = i overall = round(overall, 4) survivals = [population[max_i]] for _ in range(mi - 1): # print("wylosowano osobnika") temp = overall temp *= 10000 temp = round(temp) rand = random.randint(0, temp - 1) rand /= 10000 for i in range(len(population)): if temp_af[i] <= rand: rand -= temp_af[i] else: survivals.append(population[i]) break return survivals
def best_positions(population, d): best_value = 0 tab = [] max_x = dekoder.decode(population[0])[0] max_y = dekoder.decode(population[0])[1] max_a = dekoder.decode(population[0])[2] for i in population: dek = dekoder.decode(i) x = dek[0] temp_x = x[:] y = dek[1] temp_y = y[:] a = dek[2] temp_a = a[:] J = afunction.J(temp_x, temp_y, temp_a, d) maxx = max(J[0], best_value) if maxx != best_value: best_value = max(maxx, best_value) max_x = x max_y = y max_a = a tab = J[1] return max_x, max_y, max_a, tab
def best_v(population, d): best_value = 0 for i in population: x = dekoder.decode(i)[0] y = dekoder.decode(i)[1] a = dekoder.decode(i)[2] best_value = max(afunction.J(x, y, a, d), best_value) if best_value >= 0.9: break return best_value
def best_v(population, d): sum = 0 best_value = 0 for i in population: x = dekoder.decode(i)[0] y = dekoder.decode(i)[1] a = dekoder.decode(i)[2] value = afunction.J(x, y, a, d)[0] sum += value best_value = max(value, best_value) if best_value >= 0.9: break return best_value, sum / len(population)
def simple_J(self, element): x = dekoder.decode(element)[0] y = dekoder.decode(element)[1] a = dekoder.decode(element)[2] return afunction.J(x, y, a, self.d)