init = bd.get_init(maze) position, blocked, walked_open, returned = bd.walk(individual, maze) distance_end = math.ceil( math.sqrt(((position[0] - end[0])**2) + ((position[1] - end[1])**2))) distance_init = math.ceil( math.sqrt(((position[0] - init[0])**2) + ((position[1] - init[1])**2))) # print( # 1000 - distance_init * (blocked + returned - walked_open), # blocked, # position[0], # position[1], # ) return (individual, max_fitness - distance_end - blocked - returned) if __name__ == "__main__": maze = bd.read() result = gp.run( partial(fitness, maze), mutation_function=mt.random_replacement, crossover_function=cr.uniform, select_function=sl.stochastic_tournament, config_file="maze.cfg", ) # convergence_chart(result) maze_result = bd.simulate(result["champion"][0], maze) print(result["champion"][0]) bd.fig(maze_result, "./out/maze_result.png")
rl, rs = normalization(ind) r = -1 FOn = (30 * rs + 40 * rl) / 1360 Hn = max(0, (rs + 2 * rl - 40)) / 16 fit = FOn + r * Hn return ind, fit if __name__ == "__main__": result = gp.run( fitness, mutation_function=mt.bit_flip, crossover_function=cr.two_points, select_function=sl.fitness_proportionate_selection, config_file="radio.cfg", phenotype=show, ) convergence_chart(result, False) plot_runs(result) """ conjunto: radio standart, luxo dominio: rs [0-24] -> 5 bits rl [0-16] -> 5 bits cromosomo: 10bits rs + 2rl =< 40
return individual, (fit * 0.8 + profit * 0.2) / max_fit if __name__ == "__main__": parse("p_queens.cfg") array_length = int(environ.get("DIM")) profit_array = np.array(list(map(float, range(1, array_length**2 + 1)))) op, po = math.sqrt, math.log10 for i in range(len(profit_array)): profit_array[i] = op(profit_array[i]) if not (i + 1) % array_length: po, op = op, po continue max_fit_profit = sum(sorted(profit_array)[-1:-array_length - 1:-1]) # print(fitness(np.array([7, 5, 3, 1, 6, 8, 2, 4]))) result = gp.run( fitness, mutation_function=mt.swap, crossover_function=cr.pmx, select_function=sl.stochastic_tournament, config_file="p_queens.cfg", phenotype=show_table, pool_size=4, ) convergence_chart(result, False) plot_runs(result)