{"id":25365875,"url":"https://github.com/willguimont/simplegeneticalgorithm","last_synced_at":"2025-10-07T19:05:07.748Z","repository":{"id":111211231,"uuid":"148943723","full_name":"willGuimont/SimpleGeneticAlgorithm","owner":"willGuimont","description":"Simple Genetic Algorithm written in Python","archived":false,"fork":false,"pushed_at":"2019-06-15T20:47:26.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-05T03:02:45.076Z","etag":null,"topics":["dna","genetic-algorithm","python","python-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willGuimont.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-15T22:10:18.000Z","updated_at":"2022-01-09T20:19:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"2798592e-86c4-4a24-b83e-15af8e61a192","html_url":"https://github.com/willGuimont/SimpleGeneticAlgorithm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willGuimont%2FSimpleGeneticAlgorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willGuimont%2FSimpleGeneticAlgorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willGuimont%2FSimpleGeneticAlgorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willGuimont%2FSimpleGeneticAlgorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willGuimont","download_url":"https://codeload.github.com/willGuimont/SimpleGeneticAlgorithm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247984652,"owners_count":21028542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dna","genetic-algorithm","python","python-library"],"created_at":"2025-02-14T23:51:02.006Z","updated_at":"2025-10-07T19:05:07.683Z","avatar_url":"https://github.com/willGuimont.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleGeneticAlgorithm\n\nReally simple genetic algorithm in Python\n\n# Example\n\n```python\nimport random\n\nimport random_generator\nfrom dna import DNA\n\nTARGET = 'This is the target'\nLENGTH_TARGET = len(TARGET)\nPOPULATION_SIZE = 100\nAGENTS_INDEX = 0\nFITNESS_SCORES_INDEX = 1\n\ndef fitness(agent):\n    correct = 0\n    for i in range(LENGTH_TARGET):\n        if TARGET[i] == agent.dna[i]:\n            correct += 1\n    return correct / LENGTH_TARGET\n\n\nlast_population = []\ncurrent_population = [[], []]  # current_population[0] = agent\n                               # current_population[1] = fitness\n\nfor _ in range(POPULATION_SIZE):\n    agent = DNA(size=LENGTH_TARGET, random_generator=random_generator.RandomLetterGenerator())\n    fitness_score = fitness(agent)\n    current_population[AGENTS_INDEX].append(agent)\n    current_population[FITNESS_SCORES_INDEX].append(fitness_score)\n\nbest_dna = ''\nwhile best_dna != TARGET:\n    last_population = current_population\n    current_population = [[], []]\n    for i in range(POPULATION_SIZE):\n        random_agent, another_random_agent = random.choices(population=last_population[AGENTS_INDEX], weights=last_population[FITNESS_SCORES_INDEX], k=2)\n        child_agent = random_agent.crossover(another_random_agent).mutated(mutation_rate=0.01)\n        child_fitness_score = fitness(child_agent)\n\n        current_population[AGENTS_INDEX].append(child_agent)\n        current_population[FITNESS_SCORES_INDEX].append(child_fitness_score)\n    best_fitness = max(current_population[FITNESS_SCORES_INDEX])\n    best_agent = current_population[AGENTS_INDEX][current_population[FITNESS_SCORES_INDEX].index(best_fitness)]\n    best_dna = ''.join(best_agent.dna)\nprint(best_dna)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillguimont%2Fsimplegeneticalgorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillguimont%2Fsimplegeneticalgorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillguimont%2Fsimplegeneticalgorithm/lists"}