Skip to content

Commit 5bb342e

Browse files
authored
Merge pull request #227 from ahmedfgad/github-actions
GitHub actions
2 parents 9d6d2f2 + 473f1a3 commit 5bb342e

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

NSGA-II/non_dominant_sorting.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import numpy
2+
3+
population = numpy.array([[20, 2.2],
4+
[60, 4.4],
5+
[65, 3.5],
6+
[15, 4.4],
7+
[55, 4.5],
8+
[50, 1.8],
9+
[80, 4.0],
10+
[25, 4.6]])
11+
12+
def non_dominant_sorting(curr_set):
13+
# List of the members of the current dominant front/set.
14+
dominant_set = []
15+
# List of the non-members of the current dominant front/set.
16+
non_dominant_set = []
17+
for idx1, sol1 in enumerate(curr_set):
18+
# Flag indicates whether the solution is a member of the current dominant set.
19+
is_dominant = True
20+
for idx2, sol2 in enumerate(curr_set):
21+
if idx1 == idx2:
22+
continue
23+
# Zipping the 2 solutions so the corresponding genes are in the same list.
24+
# The returned array is of size (N, 2) where N is the number of genes.
25+
b = numpy.array(list(zip(sol1, sol2)))
26+
27+
#TODO Consider repacing < by > for maximization problems.
28+
# Checking for if any solution dominates the current solution by applying the 2 conditions.
29+
# le_eq: All elements must be True.
30+
# le: Only 1 element must be True.
31+
le_eq = b[:, 1] <= b[:, 0]
32+
le = b[:, 1] < b[:, 0]
33+
34+
# If the 2 conditions hold, then a solution dominates the current solution.
35+
# The current solution is not considered a member of the dominant set.
36+
if le_eq.all() and le.any():
37+
# print(f"{sol2} dominates {sol1}")
38+
# Set the is_dominant flag to False to not insert the current solution in the current dominant set.
39+
# Instead, insert it into the non-dominant set.
40+
is_dominant = False
41+
non_dominant_set.append(sol1)
42+
break
43+
else:
44+
# Reaching here means the solution does not dominant the current solution.
45+
# print(f"{sol2} does not dominate {sol1}")
46+
pass
47+
48+
# If the flag is True, then no solution dominates the current solution.
49+
if is_dominant:
50+
dominant_set.append(sol1)
51+
52+
# Return the dominant and non-dominant sets.
53+
return dominant_set, non_dominant_set
54+
55+
dominant_set = []
56+
non_dominant_set = population.copy()
57+
while len(non_dominant_set) > 0:
58+
d1, non_dominant_set = non_dominant_sorting(non_dominant_set)
59+
dominant_set.append(d1)
60+
61+
for i, s in enumerate(dominant_set):
62+
print(f'Dominant Front Set {i+1}:\n{s}')

docs/source/releases.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ Release Date 20 June 2023
13611361
solve the duplicates between the 2 genes by simply replacing the
13621362
value of one gene by another gene. This release tries to solve such
13631363
duplicates by looking for a third gene that will help in solving the
1364-
duplicates. These examples explain how it works. Check `this
1364+
duplicates. Check `this
13651365
section <https://pygad.readthedocs.io/en/latest/pygad.html#prevent-duplicates-in-gene-values>`__
13661366
for more information.
13671367

@@ -1887,6 +1887,11 @@ Research Papers using PyGAD
18871887

18881888
A number of research papers used PyGAD and here are some of them:
18891889

1890+
- Alberto Meola, Manuel Winkler, Sören Weinrich, Metaheuristic
1891+
optimization of data preparation and machine learning hyperparameters
1892+
for prediction of dynamic methane production, Bioresource Technology,
1893+
Volume 372, 2023, 128604, ISSN 0960-8524.
1894+
18901895
- Jaros, Marta, and Jiri Jaros. "Performance-Cost Optimization of
18911896
Moldable Scientific Workflows."
18921897

0 commit comments

Comments
 (0)