Skip to content

Commit e0ac111

Browse files
committed
Reformat comments
1 parent 8cd1d90 commit e0ac111

37 files changed

Lines changed: 266 additions & 471 deletions

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ __pycache__/
1616
docs/build/
1717
.venv-docs/
1818

19+
# =============================================================================
20+
# Local virtual environment (setup_venv.sh).
21+
# =============================================================================
22+
.venv/
23+
1924
# =============================================================================
2025
# IDE settings: JetBrains (PyCharm, IntelliJ, etc.) workspace files.
2126
# These are personal to each developer and should not be committed.

‎docs/source/benchmarks.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Benchmark Problems
22

3-
PyGAD ships a small collection of standard benchmark problems under `pygad.benchmarks`. Each problem is a class that can be called with the PyGAD fitness signature `(ga, solution, sol_idx)` and returns a fitness value in PyGAD's maximization format (the original minimization values are negated for you).
3+
PyGAD bundles common benchmark problems under `pygad.benchmarks`. Each problem is a class callable with `(ga, solution, sol_idx)` and returns a fitness in PyGAD's maximisation format. Minimisation values are negated.
44

5-
Each class also exposes the attributes you usually need to set up the GA:
5+
Class attributes for setting up the GA:
66

77
- `num_genes`: number of decision variables.
8-
- `num_objectives`: number of objectives. `1` for single-objective problems.
8+
- `num_objectives`: number of objectives (`1` for single-objective).
99
- `bounds`: `(low, high)` tuple of variable bounds.
1010

11-
For ZDT problems and ZDT4 / ZDT6, the class also has a `pareto_front(num_points)` method that returns reference points on the true Pareto front. Pass these to the IGD or GD indicators as the `reference_front` argument.
11+
ZDT classes also have a `pareto_front(num_points)` method that returns true-front reference points. Pass these to the IGD or GD indicators as `reference_front`.
1212

13-
One runnable example per benchmark is available under `examples/benchmarks/`.
13+
A runnable example per benchmark lives under `examples/benchmarks/`.
1414

1515
## Single-Objective Problems
1616

@@ -28,7 +28,7 @@ Available in `pygad.benchmarks.classic`:
2828

2929
## Multi-Objective Problems (ZDT family)
3030

31-
Available in `pygad.benchmarks.zdt`. All ZDT problems have two objectives and variables in `[0, 1]` (except ZDT4 which uses `[-5, 5]` for the rest of the variables).
31+
In `pygad.benchmarks.zdt`. Two objectives, variables in `[0, 1]` (ZDT4 uses `[-5, 5]` for the rest).
3232

3333
| Class | Pareto front shape |
3434
|---|---|
@@ -40,7 +40,7 @@ Available in `pygad.benchmarks.zdt`. All ZDT problems have two objectives and va
4040

4141
## Many-Objective Problems (DTLZ family)
4242

43-
Available in `pygad.benchmarks.dtlz`. All DTLZ problems support an arbitrary number of objectives `M`. The number of decision variables is `M + k - 1` where `k` is a "distance" variable count.
43+
In `pygad.benchmarks.dtlz`. Any number of objectives `M`. Decision variables: `M + k - 1`, where `k` is the distance-variable count.
4444

4545
| Class | Default M | Pareto front shape |
4646
|---|---|---|
@@ -51,13 +51,13 @@ Available in `pygad.benchmarks.dtlz`. All DTLZ problems support an arbitrary num
5151

5252
## Combinatorial Problems
5353

54-
Two combinatorial benchmarks are available: the 0/1 `Knapsack` and the `TSP`.
54+
Two combinatorial benchmarks: 0/1 `Knapsack` and `TSP`.
5555

5656
### Knapsack
5757

58-
Available in `pygad.benchmarks.knapsack`. The 0/1 `Knapsack` class takes three arguments: a 1D array of item `weights`, a 1D array of item `values`, and a numeric `capacity`. A solution is a binary vector where a 1 means the item is picked. The fitness is the total value when the candidate is within the capacity, and a negative penalty scaled by how much the candidate is over the limit otherwise.
58+
In `pygad.benchmarks.knapsack`. `Knapsack` takes three arguments: 1D arrays of `weights` and `values`, and a numeric `capacity`. A solution is a binary vector (1 = pick the item). Fitness is the total value within capacity, or a negative penalty scaled by the overweight amount.
5959

60-
The class exposes `gene_space=[0, 1]` and `gene_type=int` so you can plug it directly into PyGAD:
60+
Class attributes `gene_space=[0, 1]` and `gene_type=int` plug into PyGAD as is:
6161

6262
```python
6363
import pygad
@@ -81,9 +81,9 @@ ga.run()
8181

8282
### Travelling Salesman Problem
8383

84-
Available in `pygad.benchmarks.tsp`. The `TSP` class can be built from either a 2D array of city `coordinates` or a square `distance_matrix`. A solution is a permutation of the city indices and the fitness is the negative tour length (the tour closes back to the first city). Any non-permutation candidate gets a large negative penalty so the GA keeps a gradient toward feasibility.
84+
In `pygad.benchmarks.tsp`. Build `TSP` from either a 2D `coordinates` array or a square `distance_matrix`. A solution is a permutation of city indices and the fitness is the negative tour length (the tour closes back to the start). Non-permutation candidates get a large negative penalty.
8585

86-
The class exposes `gene_space=list(range(num_cities))`, `gene_type=int`, and `allow_duplicate_genes=False` so the permutation constraint is respected:
86+
Class attributes `gene_space=list(range(num_cities))`, `gene_type=int`, and `allow_duplicate_genes=False` keep the permutation constraint:
8787

8888
```python
8989
import pygad
@@ -156,7 +156,7 @@ ga = pygad.GA(
156156
)
157157
ga.run()
158158

159-
# Measure how close the final population is to the true Pareto front
159+
# IGD against the true front.
160160
true_front = problem.pareto_front(num_points=100)
161161
igd = inverted_generational_distance(ga.last_generation_fitness, true_front)
162162
print(f'IGD = {igd}')

‎docs/source/utils.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ true_front = problem.pareto_front(num_points=100)
369369
igd = inverted_generational_distance(fitness, true_front)
370370
```
371371

372-
One runnable example per indicator is available under `examples/quality_indicators/`.
372+
A runnable example per indicator lives under `examples/quality_indicators/`.
373373

374374
## More about the Operators
375375

‎examples/benchmarks/example_classic_ackley.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Run PyGAD on the Ackley benchmark from `pygad.benchmarks.classic`.
3-
4-
Ackley has a near-flat outer region with a deep, narrow basin at
5-
the origin where f(x) = 0.
6-
"""
1+
"""Run PyGAD on the Ackley benchmark. Flat outside, deep basin at the origin."""
72

83
import pygad
94
from pygad.benchmarks.classic import Ackley

‎examples/benchmarks/example_classic_griewank.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Run PyGAD on the Griewank benchmark from `pygad.benchmarks.classic`.
3-
4-
Griewank has many local minima spread over a wide area. The global
5-
minimum is at the origin where f(x) = 0.
6-
"""
1+
"""Run PyGAD on the Griewank benchmark. Many local minima, global at the origin."""
72

83
import pygad
94
from pygad.benchmarks.classic import Griewank

‎examples/benchmarks/example_classic_himmelblau.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
"""
2-
Run PyGAD on the 2D Himmelblau benchmark from
3-
`pygad.benchmarks.classic`.
4-
5-
Himmelblau has four equal global minima at f(x, y) = 0:
6-
(3.0, 2.0),
7-
(-2.805, 3.131),
8-
(-3.779, -3.283),
9-
(3.584, -1.848).
10-
"""
1+
"""Run PyGAD on the 2D Himmelblau benchmark. Four global minima at f = 0."""
112

123
import pygad
134
from pygad.benchmarks.classic import Himmelblau

‎examples/benchmarks/example_classic_rastrigin.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Run PyGAD on the Rastrigin benchmark from `pygad.benchmarks.classic`.
3-
4-
Rastrigin has many local minima placed at regular spaces. The global
5-
minimum is at the origin where f(x) = 0.
6-
"""
1+
"""Run PyGAD on the Rastrigin benchmark. Many local minima, global at the origin."""
72

83
import pygad
94
from pygad.benchmarks.classic import Rastrigin

‎examples/benchmarks/example_classic_rosenbrock.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Run PyGAD on the Rosenbrock benchmark from `pygad.benchmarks.classic`.
3-
4-
The global minimum is at x = (1, 1, ..., 1) where f(x) = 0. The
5-
minimum lives at the bottom of a long, narrow, banana-shaped valley.
6-
"""
1+
"""Run PyGAD on the Rosenbrock benchmark. Minimum sits in a narrow banana-shaped valley."""
72

83
import pygad
94
from pygad.benchmarks.classic import Rosenbrock

‎examples/benchmarks/example_classic_schwefel.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
"""
2-
Run PyGAD on the Schwefel benchmark from `pygad.benchmarks.classic`.
3-
4-
The global minimum sits at x = (420.9687, ..., 420.9687) far from
5-
the next-best local minimum, so the function is hard for many
6-
algorithms.
7-
"""
1+
"""Run PyGAD on the Schwefel benchmark. Global minimum at (420.9687, ...)."""
82

93
import pygad
104
from pygad.benchmarks.classic import Schwefel

‎examples/benchmarks/example_classic_sphere.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
"""
2-
Run PyGAD on the Sphere benchmark from `pygad.benchmarks.classic`.
3-
4-
The Sphere function has its global minimum at the origin where
5-
f(x) = 0. Under PyGAD's max convention the best fitness is 0.
6-
"""
1+
"""Run PyGAD on the Sphere benchmark. Best fitness is 0 (at the origin)."""
72

83
import pygad
94
from pygad.benchmarks.classic import Sphere

0 commit comments

Comments
 (0)