Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
PasaOpasen committed Apr 13, 2024
1 parent b47254c commit e0363a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions geneticalgorithm2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
continuous, integers, or mixed variables.
repo path: https://github.com/PasaOpasen/geneticalgorithm2
code docs path: https://pasaopasen.github.io/geneticalgorithm2/
"""

Expand Down
18 changes: 10 additions & 8 deletions geneticalgorithm2/geneticalgorithm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def __init__(
# self.discrete_mutation: Callable[[int, int, int], int] = None
# self.selection: Callable[[np.ndarray, int], np.ndarray] = None

self.revolution_oppositor = None
self.dup_oppositor = None
self.creator = None
self.init_oppositors = None
self.f: Callable[[array1D], float] = None
self.funtimeout: float = None
self.set_function: Callable[[np.ndarray], np.ndarray] = None
Expand Down Expand Up @@ -563,11 +567,7 @@ def run(
pop: array2D = None
scores: array1D = None

#
#
# callbacks part
#
#
#region CALLBACKS

def get_data():
"""
Expand Down Expand Up @@ -652,7 +652,7 @@ def total_middle_callback():
if flag:
set_data(data) # update global date if there was real callback step

############################################################
#endregion

start_time = time.time()
time_is_done = (
Expand All @@ -661,10 +661,10 @@ def total_middle_callback():
else (lambda: int(time.time() - start_time) >= time_limit_secs)
)

#############################################################
# Initial Population
self.set_function = set_function or GeneticAlgorithm2.default_set_function(self.f)

#region Initial population, duplicates filter, revolutionary

pop_coef, initializer_func = population_initializer

# population creator by random or with oppositions
Expand Down Expand Up @@ -811,6 +811,8 @@ def revolution(pop: array2D, scores: array1D, stagnation_count: int) -> Tuple[
args = args[:scores.size]
return combined[args], combined_scores[args]

#enregion

#
#
# START ALGORITHM LOGIC
Expand Down

0 comments on commit e0363a5

Please sign in to comment.