{"id":13438283,"url":"https://github.com/m-decoster/RsGenetic","last_synced_at":"2025-03-19T18:32:40.411Z","repository":{"id":54444799,"uuid":"47873258","full_name":"m-decoster/RsGenetic","owner":"m-decoster","description":"Genetic Algorithm library in Rust","archived":false,"fork":false,"pushed_at":"2021-01-22T07:58:54.000Z","size":3880,"stargazers_count":76,"open_issues_count":4,"forks_count":19,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-06T07:09:33.296Z","etag":null,"topics":["rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m-decoster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-12T10:07:07.000Z","updated_at":"2024-03-23T21:46:51.000Z","dependencies_parsed_at":"2022-08-13T15:50:44.279Z","dependency_job_id":null,"html_url":"https://github.com/m-decoster/RsGenetic","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-decoster%2FRsGenetic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-decoster%2FRsGenetic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-decoster%2FRsGenetic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-decoster%2FRsGenetic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m-decoster","download_url":"https://codeload.github.com/m-decoster/RsGenetic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221729842,"owners_count":16871124,"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":["rust"],"created_at":"2024-07-31T03:01:04.241Z","updated_at":"2024-10-27T20:31:54.462Z","avatar_url":"https://github.com/m-decoster.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","库","人工智能（Artificial Intelligence）","Machine Learning"],"sub_categories":["Artificial Intelligence","人工智能 Artificial Intelligence","人工智能","遗传算法（Genetic Algorithms）"],"readme":"# RsGenetic\n[![Rust Report Card](https://rust-reportcard.xuri.me/badge/github.com/m-decoster/RsGenetic)](https://rust-reportcard.xuri.me/report/github.com/m-decoster/RsGenetic)\n[![Build Status](https://travis-ci.org/m-decoster/RsGenetic.svg?branch=master)](https://travis-ci.org/m-decoster/RsGenetic)\n[![Crates Version](https://img.shields.io/crates/v/rsgenetic.svg)](https://crates.io/crates/rsgenetic/)\n[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)\n[![License Apache](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](./LICENSE)\n\n## Summary and Features\nRsGenetic is a framework for executing genetic algorithms in Rust. It is designed to have a simple but modular API.\n\n## Examples and Documentation\nDocumentation is available [here](https://docs.rs/rsgenetic).  \n\n### Implementing the `Fitness` trait\n\nNote that, if your fitness type is an integer type, you\ndo not need to write a wrapper struct around this integer. See\nthe `types` module documentation for more details.\n\n```rust\nuse rsgenetic::pheno::*;\nuse std::cmp::Ordering;\n\n#[derive(Eq, PartialEq, PartialOrd, Ord)]\nstruct MyFitness {\n    value: i32,\n}\n\nimpl Fitness for MyFitness {\n    // The zero value for our custom type\n    fn zero() -\u003e MyFitness {\n        MyFitness { value: 0 }\n    }\n\n    // The absolute difference between two instances\n    fn abs_diff(\u0026self, other: \u0026MyFitness) -\u003e MyFitness {\n        MyFitness {\n            value: (self.value - other.value).abs()\n        }\n    }\n}\n```\n\n### Implementing the `Phenotype` trait\n\nNote that we use an integer type as the fitness type parameter\nto make this example more simple. Replace it with your custom type\nif needed. In this example, we try to find individuals with\ntwo integer components that sum to a target value.\n\nThis example is far-fetched, but simplified to show how\neasy it is to define new individuals and implement\nthe `Phenotype` trait.\n\n```rust\nuse rsgenetic::pheno::*;\n\nconst TARGET: i32 = 100;\n\n#[derive(Copy, Clone)]\nstruct MyPheno {\n    x: i32,\n    y: i32,\n}\n\nimpl Phenotype\u003ci32\u003e for MyPheno {\n    // How fit is this individual?\n    fn fitness(\u0026self) -\u003e i32 {\n        TARGET - (self.x + self.y)\n    }\n\n    // Have two individuals create a new individual\n    fn crossover(\u0026self, other: \u0026MyPheno) -\u003e MyPheno {\n        MyPheno {\n            x: self.x,\n            y: other.y,\n        }\n    }\n\n    // Mutate an individual, changing its state\n    fn mutate(\u0026self) -\u003e MyPheno {\n        MyPheno {\n            x: self.x + 1,\n            y: self.y - 1,\n        }\n    }\n}\n```\n\n### Creating and running a `Simulator`\n\n```rust\nuse rsgenetic::pheno::*;\nuse rsgenetic::sim::*;\nuse rsgenetic::sim::seq::Simulator;\nuse rsgenetic::sim::select::*;\n\nconst TARGET: i32 = 100;\n\n#[derive(Copy, Clone)]\nstruct MyPheno {\n    x: i32,\n    y: i32,\n}\n\nimpl Phenotype\u003ci32\u003e for MyPheno {\n    // How fit is this individual?\n    fn fitness(\u0026self) -\u003e i32 {\n        TARGET - (self.x + self.y)\n    }\n\n    // Have two individuals create a new individual\n    fn crossover(\u0026self, other: \u0026MyPheno) -\u003e MyPheno {\n        MyPheno {\n            x: self.x,\n            y: other.y,\n        }\n    }\n\n    // Mutate an individual, changing its state\n    fn mutate(\u0026self) -\u003e MyPheno {\n        MyPheno {\n            x: self.x + 1,\n            y: self.y - 1,\n        }\n    }\n}\n\nfn main() {\n    let mut population = (0..100).map(|i| MyPheno { x: i, y: 100 - i }).collect();\n    let mut s = Simulator::builder(\u0026mut population)\n                    .set_selector(Box::new(StochasticSelector::new(10)))\n                    .set_max_iters(50)\n                    .build();\n    s.run();\n    let result = s.get().unwrap(); // The best individual\n}\n```\n\nSee the `examples` directory in the repository for more elaborate examples.\n\n## Note\n\nThis library is currently in maintenance mode. There have been some indications that the API\nneeds an update to be more flexible, which would require an incrementation of the major version number (#23, #30).\nUnfortunately, I currently do not have the time to implement such a redesign. I will however continue to reply to issues\nand merge pull requests, but features might not be implemented by me, depending on their size.\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nContributions are always welcome. Take a look at the issues for any enhancements that need to be\ndone or bugs that need to be fixed. If you encounter any bugs while using the library, feel free to\nopen an issue and/or fix the bug, and submit pull requests.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any\nadditional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-decoster%2FRsGenetic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm-decoster%2FRsGenetic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-decoster%2FRsGenetic/lists"}