{"id":19830013,"url":"https://github.com/2003harsh/random-string-search-using-genetic-algorithm-","last_synced_at":"2025-10-04T12:43:59.497Z","repository":{"id":248644497,"uuid":"829283831","full_name":"2003HARSH/Random-string-search-using-Genetic-Algorithm-","owner":"2003HARSH","description":"This project uses a genetic algorithm to search for a target string. By evolving a population of random strings through selection, crossover, and mutation, the algorithm progressively approximates the target string over multiple generations.","archived":false,"fork":false,"pushed_at":"2024-07-19T13:45:15.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-04T12:43:58.162Z","etag":null,"topics":["genetic-algorithm","object-oriented-programming","optimization-problem","python"],"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/2003HARSH.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":"2024-07-16T06:08:23.000Z","updated_at":"2024-07-19T13:45:19.000Z","dependencies_parsed_at":"2025-01-11T09:47:00.708Z","dependency_job_id":"c726bff8-54cb-4089-94c7-22654c998a06","html_url":"https://github.com/2003HARSH/Random-string-search-using-Genetic-Algorithm-","commit_stats":null,"previous_names":["2003harsh/random-string-search-using-genetic-algorithm-"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2003HARSH/Random-string-search-using-Genetic-Algorithm-","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FRandom-string-search-using-Genetic-Algorithm-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FRandom-string-search-using-Genetic-Algorithm-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FRandom-string-search-using-Genetic-Algorithm-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FRandom-string-search-using-Genetic-Algorithm-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2003HARSH","download_url":"https://codeload.github.com/2003HARSH/Random-string-search-using-Genetic-Algorithm-/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FRandom-string-search-using-Genetic-Algorithm-/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278315189,"owners_count":25966774,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"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","object-oriented-programming","optimization-problem","python"],"created_at":"2024-11-12T11:21:16.406Z","updated_at":"2025-10-04T12:43:59.461Z","avatar_url":"https://github.com/2003HARSH.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Random String Search Using Genetic Algorithm\n\nThis project demonstrates the use of a genetic algorithm to search for a target string. The algorithm evolves a population of random strings through selection, crossover, and mutation to progressively approximate the target string.\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Classes and Methods](#classes-and-methods)\n- [Output](#output)\n- [Notes](#notes)\n- [License](#license)\n\n## Introduction\n\nGenetic algorithms are a type of optimization algorithm inspired by the process of natural selection. This project uses a genetic algorithm to find a target string by evolving a population of candidate strings over multiple generations.\n\n## Installation\n\nTo run the code, ensure you have Python installed. No additional libraries are required.\n\n## Usage\n\nThe main components of this project are the `Dna` and `Population` classes. The `Dna` class defines the crossover and mutation methods, while the `Population` class manages the population of strings, calculates fitness scores, performs natural selection, and generates new populations.\n\n### Classes and Methods\n\n#### Dna Class\n\n- **crossover(parent1, parent2)**: Combines two parent strings to create a child string.\n- **mutation(child, mutation_rate)**: Applies mutations to the child string with a given mutation rate.\n\n#### Population Class\n\n- **\\_\\_init\\_\\_(target, population_size, mutation_rate)**: Initializes the population with the given target string, population size, and mutation rate.\n- **generate_population()**: Generates an initial random population.\n- **calculate_fitness(individual)**: Calculates the fitness of an individual string based on its similarity to the target string.\n- **natural_selection()**: Selects the top individuals to form a mating pool.\n- **generate_new_population()**: Generates a new population from the mating pool using crossover and mutation.\n\n### Output\n\nThe code will print the best string found in each generation along with its fitness score. It will stop early if the target string is found.\n\n![1](https://github.com/user-attachments/assets/4c799a59-93b2-4e03-ae81-3ef57bfec2f1)\n\n## Notes\n\n- The mutation rate controls the frequency of random changes in the strings.\n- The fitness function measures the similarity of each string to the target string.\n- The code can be adjusted to work with different target strings, population sizes, and mutation rates.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2003harsh%2Frandom-string-search-using-genetic-algorithm-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2003harsh%2Frandom-string-search-using-genetic-algorithm-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2003harsh%2Frandom-string-search-using-genetic-algorithm-/lists"}