{"id":23167904,"url":"https://github.com/arkodeepsen/monarch-butterfly","last_synced_at":"2026-02-02T13:15:29.448Z","repository":{"id":268290364,"uuid":"903883727","full_name":"arkodeepsen/monarch-butterfly","owner":"arkodeepsen","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-16T12:02:57.000Z","size":666,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T22:23:50.839Z","etag":null,"topics":["butterfly","gemini-api","knapsack","knapsack-problem","knapsack-problem-dynamic","knapsack-solver","knapsack01","monarch","monarch-butterflies","monarch-butterfly-optimization"],"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/arkodeepsen.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-12-15T19:54:27.000Z","updated_at":"2024-12-18T19:38:45.000Z","dependencies_parsed_at":"2024-12-15T20:32:47.487Z","dependency_job_id":"e0dceec6-9679-45d7-b4fa-f89cfe25b35a","html_url":"https://github.com/arkodeepsen/monarch-butterfly","commit_stats":null,"previous_names":["arkodeepsen/monarch-butterfly"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arkodeepsen/monarch-butterfly","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkodeepsen%2Fmonarch-butterfly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkodeepsen%2Fmonarch-butterfly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkodeepsen%2Fmonarch-butterfly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkodeepsen%2Fmonarch-butterfly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arkodeepsen","download_url":"https://codeload.github.com/arkodeepsen/monarch-butterfly/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arkodeepsen%2Fmonarch-butterfly/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29012691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T12:48:30.580Z","status":"ssl_error","status_checked_at":"2026-02-02T12:46:38.384Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["butterfly","gemini-api","knapsack","knapsack-problem","knapsack-problem-dynamic","knapsack-solver","knapsack01","monarch","monarch-butterflies","monarch-butterfly-optimization"],"created_at":"2024-12-18T02:36:05.334Z","updated_at":"2026-02-02T13:15:29.413Z","avatar_url":"https://github.com/arkodeepsen.png","language":"Python","readme":"# 🦋 Enhanced Monarch Butterfly Optimization Algorithm with Google Gemini AI Integration\n\n## **Project Overview**\nThis project combines the Monarch Butterfly Optimization (MBO) algorithm with Google Gemini AI to address optimization problems such as the 0–1 Knapsack Problem. The MBO algorithm is enhanced for binary solutions, with Gemini AI generating problem statements, converting them into knapsack instances, and analyzing results. This integration improves solution quality, adaptability, and convergence rates.\n\n---\n\n## **Features**\n- **Google Gemini AI Integration**: Automates problem generation, instance creation, and analytical insights.\n- **Enhanced MBO Algorithm**: Tailored for discrete optimization with advanced mutation, migration, and local search.\n- **Comprehensive Visualizations**: Includes fitness convergence plots and solution selection charts.\n- **Scalable Implementation**: Supports large instances with high efficiency.\n\n---\n\n## **Project Structure**\n```\nmbo_knapsack_project/\n├── mbo_core.py             # Core implementation of the Enhanced MBO algorithm\n├── knapsack_problem.py     # Script to run the algorithm on knapsack instances\n├── utils.py                # Utility functions for visualization and analysis\n├── test_mbo_core.py        # Unit tests for the MBO algorithm\n├── data/\n│   └── knapsack_instances/ # Folder for knapsack instance files\n│       ├── instance1.txt   # Example knapsack problem instance\n│       └── ...             # Additional instances\n├── results/\n│   ├── graphs/             # Directory for output plots (fitness convergence, solutions)\n│   └── logs/               # Logs for runtime and results\n├── requirements.txt        # Python dependencies\n├── LICENSE                 # Project license\n└── README.md               # Project overview and instructions\n```\n\n---\n\n## **Getting Started**\n\nFeel free to use this project for your first or second-semester college project. Just fork and clone this repo. Here 's a step-by-step guide:\n\n1. **Star the Project**\n   - Yes, this is required for the program to function properly. Go ahead, click that star button on GitHub!\n\n2. **Read the Documentation**\n   - Make sure to read the `documentation.md` file. It’s crucial to understand how everything works so you can explain it to your teachers and look like a genius.\n\n3. **Prepare Your Presentation**\n   - Use the visualizations and results to create a stunning presentation. Your teachers will be amazed at your technical prowess!\n\n## **Installation**\n1. **Clone the Repository**\n   ```bash\n   git clone https://github.com/arkodeepsen/Monarch-Butterfly.git\n   cd monarch-butterfly\n   ```\n\n2. **Create a Virtual Environment**\n   ```bash\n   python3 -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. **Install Dependencies**\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n4. **Set Up Environment Variables**\n   - Create a `.env` file in the root directory of the project and add your Google Gemini API key:\n      ```\n      GEMINI_API_KEY=your_api_key_here\n      ```\n\n---\n\n## **Usage**\n### **Running the Knapsack Solver Manually (For Debugging \u0026 Custom Instances)**\n1. **Prepare Knapsack Instance**\n   - Add your instance files in `data/knapsack_instances/` in the format:\n     ```\n     \u003ccapacity\u003e\n     \u003cvalue1\u003e \u003cweight1\u003e\n     \u003cvalue2\u003e \u003cweight2\u003e\n     ```\n\n2. **Run the Solver**\n   ```bash\n   python knapsack_problem.py --instance data/knapsack_instances/instance1.txt --pop_size 50 --max_gen 100 --mutation_rate 0.05\n   ```\n\n3. **Parameters**\n   - `--instance`: Path to the knapsack instance file.\n   - `--pop_size`: Population size (default: 50).\n   - `--max_gen`: Number of generations (default: 100).\n   - `--mutation_rate`: Mutation probability (default: 0.01).\n   - `--save_plots`: Save plots as images in `results/graphs/`.\n\n---\n## **Automatic Usage With Interface (Recommended)**\nFor debugging purposes, you can manually run the solver as described above. However, for a more user-friendly experience, use the `main.py` script which provides a Tkinter-based UI. This interface leverages Google Gemini AI to generate real-world problems, convert them into knapsack instances, and solve them.\n\n### **Running the Tkinter UI**\n1. **Execute the Main Script**\n   ```bash\n   python main.py\n   ```\n\n2. **Features of the UI**\n   - **Problem Generation**: Automatically generate optimization problems using Google Gemini AI.\n   - **Instance Conversion**: Convert generated problems into knapsack instances.\n   - **Solution Visualization**: Visualize the solutions and fitness convergence within the UI.\n\n![Problem \u0026 Instance Generation](image-1.png)\n![Solution Generation \u0026 Visualization](image.png)\n\n---\n\n## **Example**\n```bash\npython knapsack_problem.py --instance data/knapsack_instances/instance1.txt --pop_size 50 --max_gen 100 --mutation_rate 0.05 --save_plots\n```\n- **Output**:\n  - Best solution, fitness, and runtime in the terminal.\n  - Saved plots: \n    - `fitness_convergence_\u003cinstance_name\u003e.png`\n    - `knapsack_solution_\u003cinstance_name\u003e.png`\n    - `solution_plot.png`\n    - `fitness_history.png`\n\n---\n\n## **Unit Testing**\nRun tests to validate the core functionality:\n```bash\npython -m unittest test_mbo_core.py\n```\n\n---\n\n## **Visualization**\n- **Fitness Convergence**: Tracks fitness improvements over generations.\n\n![Fitness History](fitness_history.png)\n\n- **Knapsack Solution**: Highlights selected items and their weights.\n\n![Solution Plot](solution_plot.png)\n\n---\n\n## **Contributing**\nContributions are welcome! Fork the repository, make your changes, and submit a pull request.\n\n---\n\n## **License**\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## **Acknowledgements**\nSpecial thanks to the authors of the imported modules for their invaluable tools and resources.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkodeepsen%2Fmonarch-butterfly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farkodeepsen%2Fmonarch-butterfly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farkodeepsen%2Fmonarch-butterfly/lists"}