Skip to content

Commit 60dc723

Browse files
Added Dockerfile, tests, and README
1 parent 0847642 commit 60dc723

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.oaenv/
22
.pytest_cache/
3+
tests/__pycache__/
34
build/
45
dist/
56
optimization_algorithms.egg-info/

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.9-slim
3+
4+
# Set the working directory in the container
5+
WORKDIR /usr/src/app
6+
7+
# Copy the current directory contents into the container
8+
COPY . .
9+
10+
# Install any needed packages specified in requirements.txt
11+
RUN pip install --no-cache-dir -r requirements.txt
12+
13+
# Install pytest for running tests
14+
RUN pip install pytest
15+
16+
# Run unit tests
17+
RUN pytest tests/
18+
19+
# Set the default command to run the optimization example
20+
CMD ["python", "-m", "unittest", "discover", "-s", "tests"]

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,122 @@ You can install this package directly from PyPI:
2020

2121
```bash
2222
pip install optimization_algorithms
23+
```
24+
25+
Alternatively, you can clone this repository and install it locally:
26+
27+
```bash
28+
git clone https://github.com/your-username/optimization_algorithms.git
29+
cd optimization_algorithms
30+
pip install .
31+
```
32+
33+
## How to Use
34+
35+
### Example: Unconstrained BMR Algorithm
36+
37+
```python
38+
import numpy as np
39+
from optimization_algorithms import BMR_algorithm, objective_function
40+
41+
# Define the bounds for a 2D problem
42+
bounds = np.array([[-100, 100]] * 2)
43+
44+
# Set parameters
45+
num_iterations = 100
46+
population_size = 50
47+
num_variables = 2
48+
49+
# Run the BMR algorithm
50+
best_fitness = BMR_algorithm(bounds, num_iterations, population_size, num_variables, objective_function)
51+
print(f"Best fitness found: {best_fitness}")
52+
```
53+
54+
### Example: Constrained BWR Algorithm
55+
56+
```python
57+
import numpy as np
58+
from optimization_algorithms import BWR_algorithm, objective_function, constraint_1, constraint_2
59+
60+
# Define the bounds for a 2D problem
61+
bounds = np.array([[-100, 100]] * 2)
62+
63+
# Set parameters
64+
num_iterations = 100
65+
population_size = 50
66+
num_variables = 2
67+
constraints = [constraint_1, constraint_2]
68+
69+
# Run the BWR algorithm with constraints
70+
best_fitness = BWR_algorithm(bounds, num_iterations, population_size, num_variables, objective_function, constraints)
71+
print(f"Best fitness found: {best_fitness}")
72+
```
73+
74+
### Unit Testing
75+
76+
This package comes with unit tests. To run the tests:
77+
78+
```bash
79+
python -m unittest discover -s tests
80+
```
81+
82+
You can also run the tests using Docker:
83+
84+
```bash
85+
docker build -t optimization-algorithms .
86+
docker run -it optimization-algorithms
87+
```
88+
89+
## Algorithms Overview
90+
91+
### BMR (Best-Mean-Random) Algorithm
92+
93+
The BMR algorithm is based on the best, mean, and random solutions from the population. It works by updating solutions based on their interaction with these key elements.
94+
95+
- **Paper Citation**: R. V. Rao, R. Shah, *BMR and BWR: Two simple metaphor-free optimization algorithms*. [arXiv:2407.11149v2](https://arxiv.org/abs/2407.11149).
96+
97+
### BWR (Best-Worst-Random) Algorithm
98+
99+
The BWR algorithm updates solutions by considering the best, worst, and random solutions in the population. The algorithm balances exploration and exploitation through these interactions.
100+
101+
- **Paper Citation**: R. V. Rao, R. Shah, *BMR and BWR: Two simple metaphor-free optimization algorithms*. [arXiv:2407.11149v2](https://arxiv.org/abs/2407.11149).
102+
103+
## Docker Support
104+
105+
You can use the included `Dockerfile` to build and test the package quickly. To build and run the package in Docker:
106+
107+
```bash
108+
docker build -t optimization-algorithms .
109+
docker run -it optimization-algorithms
110+
```
111+
112+
## License
113+
114+
This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.
115+
116+
## References
117+
118+
1. Ravipudi Venkata Rao, Ravikumar Shah, "BMR and BWR: Two simple metaphor-free optimization algorithms for solving real-life non-convex constrained and unconstrained problems," [arXiv:2407.11149v2](https://arxiv.org/abs/2407.11149).
119+
120+
---
121+
122+
Happy optimizing!
123+
```
124+
125+
### 5. Final Steps
126+
127+
Once you've completed the setup:
128+
1. **Commit and Push to GitHub**:
129+
```bash
130+
git add .
131+
git commit -m "Added Dockerfile, tests, and README"
132+
git push origin main
133+
```
134+
135+
2. **Test Locally**:
136+
Make sure everything works locally before sharing the package.
137+
138+
3. **Share Your Package**:
139+
You can now share the repository link, and anyone can install the package via PyPI or directly from GitHub.
140+
141+
Let me know if you need further help!

0 commit comments

Comments
 (0)