Skip to content

Commit

Permalink
rename geneticalgorithm2 class to GeneticAlgorithm2
Browse files Browse the repository at this point in the history
  • Loading branch information
PasaOpasen committed Apr 13, 2024
1 parent 8d21c4a commit fafad81
Show file tree
Hide file tree
Showing 36 changed files with 218 additions and 204 deletions.
341 changes: 175 additions & 166 deletions README.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion geneticalgorithm2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

from typing_extensions import TypeAlias

from .classes import Generation, AlgorithmParams

from .geneticalgorithm2 import geneticalgorithm2
from .geneticalgorithm2 import GeneticAlgorithm2

# to keep backward compatibility
geneticalgorithm2: TypeAlias = GeneticAlgorithm2

from .mutations import Mutations
from .crossovers import Crossover
Expand Down
8 changes: 4 additions & 4 deletions geneticalgorithm2/geneticalgorithm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endregion


class geneticalgorithm2:
class GeneticAlgorithm2:

"""
Genetic Algorithm (Elitist version) for Python3.8+
Expand Down Expand Up @@ -363,9 +363,9 @@ def _progress(self, count: int, total: int, status: str = ''):

part = count / total

filled_len = round(geneticalgorithm2.PROGRESS_BAR_LEN * part)
filled_len = round(GeneticAlgorithm2.PROGRESS_BAR_LEN * part)
percents = round(100.0 * part, 1)
bar = '|' * filled_len + '_' * (geneticalgorithm2.PROGRESS_BAR_LEN - filled_len)
bar = '|' * filled_len + '_' * (GeneticAlgorithm2.PROGRESS_BAR_LEN - filled_len)

self.progress_stream.write('\r%s %s%s %s' % (bar, percents, '%', status))
self.progress_stream.flush()
Expand Down Expand Up @@ -665,7 +665,7 @@ def total_middle_callback():

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

pop_coef, initializer_func = population_initializer

Expand Down
2 changes: 1 addition & 1 deletion tests/AlgorithmParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import numpy as np
from geneticalgorithm2 import AlgorithmParams
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def function(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/Standard GA vs. Elitist GA.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import AlgorithmParams
import matplotlib.pyplot as plt

Expand Down
2 changes: 1 addition & 1 deletion tests/_sense_of_prob_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from OppOpPopInit import set_seed
from geneticalgorithm2 import geneticalgorithm2 as ga, AlgorithmParams, plot_several_lines
from geneticalgorithm2 import GeneticAlgorithm2 as ga, AlgorithmParams, plot_several_lines

set_seed(1)

Expand Down
2 changes: 1 addition & 1 deletion tests/best_of_N.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import matplotlib.pyplot as plt

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Population_initializer


Expand Down
2 changes: 1 addition & 1 deletion tests/best_of_N_with_opp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from OppOpPopInit import OppositionOperators
from OptimizationTestFunctions import Ackley

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Population_initializer


Expand Down
2 changes: 1 addition & 1 deletion tests/best_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga


subset_size = 20 # how many objects we can choose
Expand Down
2 changes: 1 addition & 1 deletion tests/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
sys.path.append('..')

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Callbacks, MiddleCallbacks, ActionConditions


Expand Down
2 changes: 1 addition & 1 deletion tests/check_new_types_of_cross_and_mut.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Crossover, Mutations

def f(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
pen=0
Expand Down
2 changes: 1 addition & 1 deletion tests/disable_messages_and_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/init_local_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from DiscreteHillClimbing import Hill_Climbing_descent

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Population_initializer


Expand Down
2 changes: 1 addition & 1 deletion tests/min of sum int.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sys.path.append('..')

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/min of sum mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sys.path.append('..')

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/min of sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
import math
Expand Down
2 changes: 1 addition & 1 deletion tests/mut_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import AlgorithmParams

def f(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/optimization_test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

from OptimizationTestFunctions import Sphere, Ackley, AckleyTest, Rosenbrock, Fletcher, Griewank, Penalty2, Quartic, Rastrigin, SchwefelDouble, SchwefelMax, SchwefelAbs, SchwefelSin, Stairs, Abs, Michalewicz, Scheffer, Eggholder, Weierstrass

Expand Down
2 changes: 1 addition & 1 deletion tests/plot_diversities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

from geneticalgorithm2 import MiddleCallbacks

Expand Down
2 changes: 1 addition & 1 deletion tests/plot_each_gen_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
sys.path.append('..')

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

from geneticalgorithm2 import Actions, ActionConditions, MiddleCallbacks

Expand Down
2 changes: 1 addition & 1 deletion tests/plot_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import numpy as np

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

from geneticalgorithm2 import plot_pop_scores # for plotting scores without ga object

Expand Down
2 changes: 1 addition & 1 deletion tests/progress_bar_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sys.path.append('..')

import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/remove_dups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from OppOpPopInit import OppositionOperators

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga



Expand Down
2 changes: 1 addition & 1 deletion tests/remove_dups_by_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

from geneticalgorithm2 import ActionConditions, Actions, MiddleCallbacks

Expand Down
2 changes: 1 addition & 1 deletion tests/report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import numpy as np

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import plot_several_lines

def f(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/revolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from OppOpPopInit import OppositionOperators
from OptimizationTestFunctions import Eggholder

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga



Expand Down
2 changes: 1 addition & 1 deletion tests/save and load generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga


from OptimizationTestFunctions import Eggholder
Expand Down
2 changes: 1 addition & 1 deletion tests/selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np
import matplotlib.pyplot as plt

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Selection

def f(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/set_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import math
import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga


def f_slow(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/small_middle_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np

from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
from geneticalgorithm2 import Actions, ActionConditions, MiddleCallbacks
from geneticalgorithm2 import Crossover, Mutations

Expand Down
2 changes: 1 addition & 1 deletion tests/start_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/str.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down
2 changes: 1 addition & 1 deletion tests/studEA.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga
import matplotlib.pyplot as plt

def f(X):
Expand Down
2 changes: 1 addition & 1 deletion tests/time_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


import numpy as np
from geneticalgorithm2 import geneticalgorithm2 as ga
from geneticalgorithm2 import GeneticAlgorithm2 as ga

def f(X):
return np.sum(X)
Expand Down

0 comments on commit fafad81

Please sign in to comment.