Exemplo n.º 1
0
    for p in people_next:
        if ((random.randint(1, 100) / decimal.Decimal(100)) <=
                PROBABILITY_MUTATION):
            p.mutate()

    # next generation
    result = evolution(people_next, world, generation + 1)

    return result


if __name__ == '__main__':

    print('---------- TEST ----------')
    human1 = Human(10, 2, 0.01)
    human1.generate()
    human2 = Human(10, 2, 0.01)
    human2.generate()
    children12 = human1 * human2
    print('human1   : ', human1.getGeneSequence(), end=' ')
    print('human2   : ', human2.getGeneSequence())
    print('children1: ', children12[0].getGeneSequence(), end=' ')
    print('children2: ', children12[1].getGeneSequence())
    print('---------- TEST ----------')

    world = World()
    print('\r\nA world has been created.')

    people = []
    # create people with random gene sequences
    for i in range(MAX_GENES):
Exemplo n.º 2
0

if __name__ == '__main__':

    with open('./attractions.json', 'r') as f:
        data_attractions = json.load(f)

    disney_world = DisneyWorld(data_attractions["attractions"])
    print('A world named Disney has been created.')

    people = []
    # create people with random gene sequences
    for i in range(MAX_GENES):
        human = Human(LENGTH_GENE, data_attractions["number"] * 2,
                      FREQUENCY_MUTATION)
        human.generate()
        people.append(human)

    print(len(people), 'people are exploring the dream world today!')

    result = evolution(people, disney_world,
                       1)  # continue evolution up to MAX_GENERATION

    print('\r\nEvolution has finished.\r\n\r\n---------- RESULT ----------')

    # print result
    for i in range(len(result)):
        print(i, ' >>')
        print('EVALUATION  : ', result[i].getEvaluation())
        print('GENESEQUENCE: ', result[i].getGeneSequence())