def main(): network = Utils.read_berlin("exemplu.txt") gaParam = { 'popSize': 200, 'noGen': 2000, 'pc': 0.8, 'pm': 0.1 } problParam = { 'min': 1, 'max': network['noNodes'], 'fitness_function': Utils.modularity, 'noNodes': network['noNodes'], 'matrix': network['matrix'] } ga = GA(gaParam, problParam) for g in range(gaParam['noGen']): ga.generate_newGeneration() bestChromo = ga.best_chromosome() worstChromo = ga.worst_chromosome() print('Best solution in generation ' + str(g) + ' is: x = ' + str(bestChromo.repres) + ' f(x) = ' + str( bestChromo.fitness)) print('Worst solution in generation ' + str(g) + ' is: x = ' + str(worstChromo.repres) + ' f(x) = ' + str( worstChromo.fitness)) print()
def main(): network = fileUtils.read_from_directory(4) gaParam = {'size': 100, 'generations': 100} problParam = { 'noNodes': network['noNodes'], 'matrix': network['matrix'], 'function': fitness } ga = GA(gaParam, problParam) ga.initialization() ga.evaluation() for generation in range(gaParam['generations']): # ga.one_generation_steady_state() # ga.one_generation_elitism() ga.one_generation_elitism_improved() best = ga.best_chromosome() print('Solutia optima in generatia ' + str(generation + 1) + ' este ' + str(best.repres) + 'fitness = ' + str(best.fitness)) best = ga.best_chromosome() print('\nSolutia optima : ' + str(best.repres) + '\n fitness = ' + str(best.fitness))
def main(): file_name = "net.in" net = read_net(file_name) problParam = { 'graph': net['graph'], 'function': fitness_funct, 'size': net['no_nodes'] } param = {'popSize': 200, 'noGen': 5000, 'mut_rate': 50} ga = GA(param, problParam) ga.initialisation() ga.evaluation() g = 0 graph = net['graph'] while g < param['noGen']: g += 1 ga.one_generation() chromo = ga.best_chromosome() print(chromo.fitness)