-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/bpzoran/gadapt
- Loading branch information
Showing
8 changed files
with
75 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
gadapt/operations/crossover/base_crossover_event_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class BaseCrossoverEventHandler: | ||
""" | ||
Handles crossover events | ||
""" | ||
def on_decision_variable_crossed(self, *args, **kwargs): | ||
pass | ||
|
||
def on_all_decision_variable_crossed(self, *args, **kwargs): | ||
pass | ||
|
||
def pre_cross_genetic_material(self, *args, **kwargs): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
gadapt/operations/crossover/blending_parent_diversity_crossover.py
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
gadapt/operations/crossover/parent_diversity_crossover_event_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from gadapt.utils import ga_utils | ||
from gadapt.operations.crossover.base_crossover_event_handler import BaseCrossoverEventHandler | ||
|
||
|
||
class ParentDiversityCrossoverEventHandler(BaseCrossoverEventHandler): | ||
""" | ||
Handles crossover events using parent diversity mutation. | ||
""" | ||
|
||
def __init__(self): | ||
self._genetic_diversity = None | ||
|
||
def _get_genetic_diversity(self, mother_gene, father_gene) -> float: | ||
return abs( | ||
mother_gene.variable_value - father_gene.variable_value | ||
) / ( | ||
father_gene.decision_variable.max_value | ||
- father_gene.decision_variable.min_value | ||
) | ||
|
||
def _get_parent_diversity(self): | ||
return round(ga_utils.average(self._genetic_diversity), 2) | ||
|
||
def on_decision_variable_crossed(self, *args, **kwargs): | ||
mother_gene = kwargs.get('mother_gene') | ||
father_gene = kwargs.get('father_gene') | ||
if mother_gene is None or father_gene is None: | ||
return | ||
self._genetic_diversity.append(self._get_genetic_diversity(mother_gene, father_gene)) | ||
|
||
def on_all_decision_variable_crossed(self, *args, **kwargs): | ||
parent_diversity = self._get_parent_diversity() | ||
offspring1 = kwargs.get('offspring1') | ||
offspring2 = kwargs.get('offspring2') | ||
if offspring1 is None or offspring2 is None: | ||
return | ||
offspring1.parent_diversity = parent_diversity | ||
offspring2.parent_diversity = parent_diversity | ||
|
||
def pre_cross_genetic_material(self, *args, **kwargs): | ||
self._genetic_diversity = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
setup( | ||
name="gadapt", | ||
version="0.4.14", | ||
version="0.4.15", | ||
author="Zoran Jankovic", | ||
author_email="[email protected]", | ||
url="https://github.com/bpzoran/gadapt", | ||
|