Пример #1
0
    def step(self):
        while not self.found_solution:
            print('\nGenerasi ke', self.generation)

            if confirm('Lanjut? [Y/n] '):
                self.generation += 1
            else:
                print('eksekusi berakhir')
                break
Пример #2
0
def main():
    goal = prompt('Angka tujuan? [100] ', 100)
    population_size = prompt('Jumlah populasi per generasi? (x > 1) [10] ', 10, lambda x: x > 1)
    mutation_rate = prompt('Tingkat mutasi? (0 < x < 1) [0.01] ', 0.01, lambda x: 0 < x < 1)
    crossover_rate = prompt('Tingkat persilangan? (0 < x < 1) [0.90] ', 0.90, lambda x: 0 < x < 1)

    env = Environment(Numeral, goal, population_size, crossover_rate, mutation_rate)

    if confirm('Jalankan per generasi? [Y/n] '):
        env.step()
    else:
        max_generation = prompt('Generasi maksimal? [100] ', 100, lambda x: x > 1)
        env.run(max_generation)