# MonarchOpt: Monarch Butterfly Swarm Optimization
A Python implementation of the Monarch Swarm Optimization algorithm, designed for solving binary optimization problems. The algorithm is inspired by the migration behavior of monarch butterflies and uses a novel approach combining swarm intelligence with gradient-based optimization.
## Features
- Binary optimization for various problem types
- Built-in command line interface
- Automatic result saving and history tracking
- Early stopping with known optimum
- Automatic progress reporting
- Built-in timeout mechanism
- Reproducible results with seed setting
## Installation
```bash
pip install monarchopt
```
## Quick Start
```python
from monarchopt import MSO
import numpy as np
def simple_fitness(solution):
"""Example fitness function: maximize sum of elements."""
return np.sum(solution)
MSO.run(
obj_func=simple_fitness,
dim=100,
pop_size=1000,
max_iter=800,
obj_type='max',
neighbour_count=3,
gradient_strength=0.8,
base_learning_rate=0.1
)
```
## Test Examples and Data
To run the test examples (UFLP and DUF problems):
1. Clone the GitHub repository:
```bash
git clone https://github.com/gazioglue/monarchopt.git
cd monarchopt
```
2. Run UFLP solver:
```bash
python examples/solve_uflp.py examples/data/uflp/test_instances/cap71.txt
```
3. Run DUF solver:
```bash
python examples/solve_dufs.py duf1
```
### Available Command Line Options
For UFLP:
```bash
python solve_uflp.py cap71.txt --pop-size 2000 --max-iter 1000 --seed 42
```
For DUF:
```bash
python solve_dufs.py duf2 --dim 200 --pop-size 2000 --seed 42
```
## Documentation
For more detailed usage instructions and examples, see [USAGE.md](USAGE.md).
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "monarchopt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "optimization, swarm intelligence, metaheuristic, binary optimization",
"author": null,
"author_email": "Emrullah Gazioglu <emrullahgazioglu@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d2/15/55df811acb423c8a1436f2f76271014a7c0c26c5e27b70739217d2b2f848/monarchopt-0.1.2.tar.gz",
"platform": null,
"description": "# MonarchOpt: Monarch Butterfly Swarm Optimization\n\nA Python implementation of the Monarch Swarm Optimization algorithm, designed for solving binary optimization problems. The algorithm is inspired by the migration behavior of monarch butterflies and uses a novel approach combining swarm intelligence with gradient-based optimization.\n\n## Features\n\n- Binary optimization for various problem types\n- Built-in command line interface\n- Automatic result saving and history tracking\n- Early stopping with known optimum\n- Automatic progress reporting\n- Built-in timeout mechanism\n- Reproducible results with seed setting\n\n## Installation\n\n```bash\npip install monarchopt\n```\n\n## Quick Start\n\n```python\nfrom monarchopt import MSO\nimport numpy as np\n\ndef simple_fitness(solution):\n \"\"\"Example fitness function: maximize sum of elements.\"\"\"\n return np.sum(solution)\n\nMSO.run(\n obj_func=simple_fitness,\n dim=100,\n pop_size=1000,\n max_iter=800,\n obj_type='max',\n neighbour_count=3,\n gradient_strength=0.8,\n base_learning_rate=0.1\n)\n```\n\n## Test Examples and Data\n\nTo run the test examples (UFLP and DUF problems):\n\n1. Clone the GitHub repository:\n```bash\ngit clone https://github.com/gazioglue/monarchopt.git\ncd monarchopt\n```\n\n2. Run UFLP solver:\n```bash\npython examples/solve_uflp.py examples/data/uflp/test_instances/cap71.txt\n```\n\n3. Run DUF solver:\n```bash\npython examples/solve_dufs.py duf1\n```\n\n### Available Command Line Options\n\nFor UFLP:\n```bash\npython solve_uflp.py cap71.txt --pop-size 2000 --max-iter 1000 --seed 42\n```\n\nFor DUF:\n```bash\npython solve_dufs.py duf2 --dim 200 --pop-size 2000 --seed 42\n```\n\n## Documentation\n\nFor more detailed usage instructions and examples, see [USAGE.md](USAGE.md).\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python implementation of Monarch Swarm Optimization algorithm",
"version": "0.1.2",
"project_urls": {
"Changelog": "https://github.com/gazioglue/monarchopt/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/gazioglue/monarchopt#readme",
"Homepage": "https://github.com/gazioglue/monarchopt",
"Repository": "https://github.com/gazioglue/monarchopt.git",
"Usage": "https://github.com/gazioglue/monarchopt/blob/main/USAGE.md"
},
"split_keywords": [
"optimization",
" swarm intelligence",
" metaheuristic",
" binary optimization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "021e923a41cc2df0cc6d0bbe792b8d88974b8b4080ce0116849656ba1f173974",
"md5": "b2f21031255cb0377b7aa26eff2b0859",
"sha256": "0b19f7cc564d898454c826d3c07bfbc704ac35bfc1c7a167809af070724c765c"
},
"downloads": -1,
"filename": "monarchopt-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b2f21031255cb0377b7aa26eff2b0859",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9420,
"upload_time": "2025-01-05T20:01:18",
"upload_time_iso_8601": "2025-01-05T20:01:18.079121Z",
"url": "https://files.pythonhosted.org/packages/02/1e/923a41cc2df0cc6d0bbe792b8d88974b8b4080ce0116849656ba1f173974/monarchopt-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d21555df811acb423c8a1436f2f76271014a7c0c26c5e27b70739217d2b2f848",
"md5": "164ee8d369b4f50314551a6f8f7b1d07",
"sha256": "eeeb7af07188bf955ab02f2d7916692531a0915edfb75be10f06525f3fc64e0d"
},
"downloads": -1,
"filename": "monarchopt-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "164ee8d369b4f50314551a6f8f7b1d07",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10655,
"upload_time": "2025-01-05T20:01:20",
"upload_time_iso_8601": "2025-01-05T20:01:20.568785Z",
"url": "https://files.pythonhosted.org/packages/d2/15/55df811acb423c8a1436f2f76271014a7c0c26c5e27b70739217d2b2f848/monarchopt-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-05 20:01:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gazioglue",
"github_project": "monarchopt",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "monarchopt"
}