Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions #227

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions NSGA-II/non_dominant_sorting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import numpy

population = numpy.array([[20, 2.2],
[60, 4.4],
[65, 3.5],
[15, 4.4],
[55, 4.5],
[50, 1.8],
[80, 4.0],
[25, 4.6]])

def non_dominant_sorting(curr_set):
# List of the members of the current dominant front/set.
dominant_set = []
# List of the non-members of the current dominant front/set.
non_dominant_set = []
for idx1, sol1 in enumerate(curr_set):
# Flag indicates whether the solution is a member of the current dominant set.
is_dominant = True
for idx2, sol2 in enumerate(curr_set):
if idx1 == idx2:
continue
# Zipping the 2 solutions so the corresponding genes are in the same list.
# The returned array is of size (N, 2) where N is the number of genes.
b = numpy.array(list(zip(sol1, sol2)))

#TODO Consider repacing < by > for maximization problems.
# Checking for if any solution dominates the current solution by applying the 2 conditions.
# le_eq: All elements must be True.
# le: Only 1 element must be True.
le_eq = b[:, 1] <= b[:, 0]
le = b[:, 1] < b[:, 0]

# If the 2 conditions hold, then a solution dominates the current solution.
# The current solution is not considered a member of the dominant set.
if le_eq.all() and le.any():
# print(f"{sol2} dominates {sol1}")
# Set the is_dominant flag to False to not insert the current solution in the current dominant set.
# Instead, insert it into the non-dominant set.
is_dominant = False
non_dominant_set.append(sol1)
break
else:
# Reaching here means the solution does not dominant the current solution.
# print(f"{sol2} does not dominate {sol1}")
pass

# If the flag is True, then no solution dominates the current solution.
if is_dominant:
dominant_set.append(sol1)

# Return the dominant and non-dominant sets.
return dominant_set, non_dominant_set

dominant_set = []
non_dominant_set = population.copy()
while len(non_dominant_set) > 0:
d1, non_dominant_set = non_dominant_sorting(non_dominant_set)
dominant_set.append(d1)

for i, s in enumerate(dominant_set):
print(f'Dominant Front Set {i+1}:\n{s}')
7 changes: 6 additions & 1 deletion docs/source/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ Release Date 20 June 2023
solve the duplicates between the 2 genes by simply replacing the
value of one gene by another gene. This release tries to solve such
duplicates by looking for a third gene that will help in solving the
duplicates. These examples explain how it works. Check `this
duplicates. Check `this
section <https://pygad.readthedocs.io/en/latest/pygad.html#prevent-duplicates-in-gene-values>`__
for more information.

Expand Down Expand Up @@ -1887,6 +1887,11 @@ Research Papers using PyGAD

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

- Alberto Meola, Manuel Winkler, Sören Weinrich, Metaheuristic
optimization of data preparation and machine learning hyperparameters
for prediction of dynamic methane production, Bioresource Technology,
Volume 372, 2023, 128604, ISSN 0960-8524.

- Jaros, Marta, and Jiri Jaros. "Performance-Cost Optimization of
Moldable Scientific Workflows."

Expand Down