{"id":22355768,"url":"https://github.com/zbo14/genalg","last_synced_at":"2026-07-16T22:31:19.606Z","repository":{"id":94588713,"uuid":"116159131","full_name":"zbo14/genalg","owner":"zbo14","description":"genetic algorithm from ai-junkie tutorial","archived":false,"fork":false,"pushed_at":"2018-01-19T20:30:50.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-26T01:49:14.593Z","etag":null,"topics":["genetic-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zbo14.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-01-03T16:35:56.000Z","updated_at":"2018-02-06T22:44:18.000Z","dependencies_parsed_at":"2023-03-02T04:46:34.232Z","dependency_job_id":null,"html_url":"https://github.com/zbo14/genalg","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zbo14/genalg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Fgenalg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Fgenalg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Fgenalg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Fgenalg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbo14","download_url":"https://codeload.github.com/zbo14/genalg/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Fgenalg/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35560451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-16T02:00:06.687Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["genetic-algorithm"],"created_at":"2024-12-04T14:07:55.965Z","updated_at":"2026-07-16T22:31:19.600Z","avatar_url":"https://github.com/zbo14.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# genalg\n\ngenetic algorithm in python, adapted from this [tutorial](http://www.ai-junkie.com/ga/intro/gat1.html).\n\n## Example:\n\nTo run the example: `python3 genalg/example.py`\n\n```python\nfrom genalg import *\n\nif __name__ == '__main__':\n\n    ## define operator and objective functions\n\n    def add(x, y):\n        return x + y\n\n    def sub(x, y):\n        return x - y\n\n    def mul(x, y):\n        return x * y\n\n    def div(x, y):\n        return x / y\n\n    def objective(target, value):\n        diff = abs(target - value)\n        if diff \u003e 0:\n            return 1 / diff\n        return float(\"inf\")\n\n    # create operators\n\n    plus = Op('+', add)  \n\n    minus = Op('-', sub)\n\n    multiply = Op('*', mul)\n\n    divide = Op('/', div)\n\n    ## create genome\n\n    genome = Genome([1, 2, 3, 4, 5, 6, 7, 8, 9, plus, minus, multiply, divide])\n\n    ## create and run environment\n\n    env = Environment(\n        genome=genome,\n        chrom_length=300,\n        cross_rate=0.7,\n        max_iters=400,\n        mut_rate=0.01,\n        objective=objective,\n        pop_size=100,\n        target=50\n    )\n\n    (soln, iters) = env.run()\n\n    ## print the solution and the number of iterations\n    ## if solution wasn't found, iters should equal max_iters\n\n    print('Solution (iters=%d): %s' % (iters, soln))\n\n    ## example output:\n    ## Solution (iters=4): 2-2-9+8-7+3+6-1+4+4*7-7+1=50\n    ## Note: doesn't follow order of operations; just go left to right\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Fgenalg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbo14%2Fgenalg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Fgenalg/lists"}