Skip to content

Commit

Permalink
Fix: Resolve module import conflicts in pycellga package configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
SevgiAkten committed Nov 28, 2024
1 parent 7b4c9cf commit c7aaeb5
Show file tree
Hide file tree
Showing 127 changed files with 301 additions and 258 deletions.
4 changes: 2 additions & 2 deletions pycellga/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from numpy import random
import numpy as np
import random as rd
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem


class GeneType(Enum):
Expand Down Expand Up @@ -109,7 +109,7 @@ def randomize(self):
self.chromosome = [rd.uniform(-1.0, 0.1) for i in range(self.ch_size)]

else:
raise NotImplementedError(self.gen_type + " not implemented yet.")
raise NotImplementedError("This gen_type not implemented yet.")
return self.chromosome


Expand Down
4 changes: 2 additions & 2 deletions pycellga/mutation/bit_flip_mutation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class BitFlipMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/byte_mutation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from individual import *
from problems.abstract_problem import AbstractProblem
import struct
from pycellga.mutation.mutation_operator import MutationOperator
from mutation.mutation_operator import MutationOperator

class ByteMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/byte_mutation_random.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from individual import *
from problems.abstract_problem import AbstractProblem
import struct
from pycellga.mutation.mutation_operator import MutationOperator
from mutation.mutation_operator import MutationOperator

class ByteMutationRandom(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/float_uniform_mutation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from individual import *
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class FloatUniformMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/insertion_mutation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from individual import *
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class InsertionMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/shuffle_mutation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import random as rd
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from individual import *
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class ShuffleMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/swap_mutation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from individual import *
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class SwapMutation(MutationOperator):
"""
Expand Down
6 changes: 3 additions & 3 deletions pycellga/mutation/two_opt_mutation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator
from individual import *
from problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator

class TwoOptMutation(MutationOperator):
"""
Expand Down
111 changes: 77 additions & 34 deletions pycellga/optimizer.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,94 @@
# ------ Optimizer for cga, sync_ga, alpha_cga, ccga and mcccga methods ------ #


# ------------------------------ selection --------------------------------- #
from pycellga.selection.roulette_wheel_selection import RouletteWheelSelection
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.selection.selection_operator import SelectionOperator
from selection.roulette_wheel_selection import RouletteWheelSelection
from selection.tournament_selection import TournamentSelection
from selection.selection_operator import SelectionOperator
# -------------------------------------------------------------------------- #

# ------------------------------ recombination ----------------------------- #
from pycellga.recombination.one_point_crossover import OnePointCrossover
from pycellga.recombination.pmx_crossover import PMXCrossover
from pycellga.recombination.two_point_crossover import TwoPointCrossover
from pycellga.recombination.uniform_crossover import UniformCrossover
from pycellga.recombination.byte_uniform_crossover import ByteUniformCrossover
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.recombination.flat_crossover import FlatCrossover
from pycellga.recombination.arithmetic_crossover import ArithmeticCrossover
from pycellga.recombination.blxalpha_crossover import BlxalphaCrossover
from pycellga.recombination.linear_crossover import LinearCrossover
from pycellga.recombination.unfair_avarage_crossover import UnfairAvarageCrossover
from pycellga.recombination.recombination_operator import RecombinationOperator
from recombination.one_point_crossover import OnePointCrossover
from recombination.pmx_crossover import PMXCrossover
from recombination.two_point_crossover import TwoPointCrossover
from recombination.uniform_crossover import UniformCrossover
from recombination.byte_uniform_crossover import ByteUniformCrossover
from recombination.byte_one_point_crossover import ByteOnePointCrossover
from recombination.flat_crossover import FlatCrossover
from recombination.arithmetic_crossover import ArithmeticCrossover
from recombination.blxalpha_crossover import BlxalphaCrossover
from recombination.linear_crossover import LinearCrossover
from recombination.unfair_avarage_crossover import UnfairAvarageCrossover
from recombination.recombination_operator import RecombinationOperator
# -------------------------------------------------------------------------- #

# -------------------------------- mutation -------------------------------- #
from pycellga.mutation.bit_flip_mutation import BitFlipMutation
from pycellga.mutation.byte_mutation import ByteMutation
from pycellga.mutation.byte_mutation_random import ByteMutationRandom
from pycellga.mutation.insertion_mutation import InsertionMutation
from pycellga.mutation.shuffle_mutation import ShuffleMutation
from pycellga.mutation.swap_mutation import SwapMutation
from pycellga.mutation.two_opt_mutation import TwoOptMutation
from pycellga.mutation.float_uniform_mutation import FloatUniformMutation
from pycellga.mutation.mutation_operator import MutationOperator
from mutation.bit_flip_mutation import BitFlipMutation
from mutation.byte_mutation import ByteMutation
from mutation.byte_mutation_random import ByteMutationRandom
from mutation.insertion_mutation import InsertionMutation
from mutation.shuffle_mutation import ShuffleMutation
from mutation.swap_mutation import SwapMutation
from mutation.two_opt_mutation import TwoOptMutation
from mutation.float_uniform_mutation import FloatUniformMutation
from mutation.mutation_operator import MutationOperator
# -------------------------------------------------------------------------- #


# ------------------- problems.single_objective.continuous -------------------------------- #
from problems.single_objective.continuous.ackley import *
from problems.single_objective.continuous.bentcigar import Bentcigar
from problems.single_objective.continuous.bohachevsky import Bohachevsky
from problems.single_objective.continuous.chichinadze import Chichinadze
from problems.single_objective.continuous.dropwave import Dropwave
from problems.single_objective.continuous.fms import Fms
from problems.single_objective.continuous.griewank import Griewank
from problems.single_objective.continuous.holzman import Holzman
from problems.single_objective.continuous.levy import Levy
from problems.single_objective.continuous.matyas import Matyas
from problems.single_objective.continuous.pow import Pow
from problems.single_objective.continuous.powell import Powell
from problems.single_objective.continuous.rastrigin import Rastrigin
from problems.single_objective.continuous.rosenbrock import Rosenbrock
from problems.single_objective.continuous.rothellipsoid import Rothellipsoid
from problems.single_objective.continuous.schaffer import Schaffer
from problems.single_objective.continuous.schaffer2 import Schaffer2
from problems.single_objective.continuous.schwefel import Schwefel
from problems.single_objective.continuous.sphere import Sphere
from problems.single_objective.continuous.styblinskitang import StyblinskiTang
from problems.single_objective.continuous.sumofdifferentpowers import Sumofdifferentpowers
from problems.single_objective.continuous.threehumps import Threehumps
from problems.single_objective.continuous.zakharov import Zakharov
from problems.single_objective.continuous.zettle import Zettle
# ----------------------------------------------------------------------------------------------- #


# ------------------- problems.single_objective.discrete.binary -------------------------------- #
from problems.single_objective.discrete.binary.count_sat import CountSat
from problems.single_objective.discrete.binary.ecc import Ecc
from problems.single_objective.discrete.binary.maxcut20_01 import Maxcut20_01
from problems.single_objective.discrete.binary.maxcut20_09 import Maxcut20_09
from problems.single_objective.discrete.binary.maxcut100 import Maxcut100
from problems.single_objective.discrete.binary.mmdp import Mmdp
from problems.single_objective.discrete.binary.one_max import OneMax
from problems.single_objective.discrete.binary.peak import Peak
# ----------------------------------------------------------------------------------------------- #


# ------------------- problems.single_objective.discrete.permutation.tsp ------------------------ #
from problems.single_objective.discrete.permutation.tsp import Tsp
# ----------------------------------------------------------------------------------------------- #




import random
import numpy as np
import byte_operators
from pycellga.population import *
from pycellga.individual import *
from pycellga.mutation.bit_flip_mutation import *
from pycellga.selection.tournament_selection import *
from pycellga.recombination.one_point_crossover import *
from pycellga.problems.single_objective.discrete.binary.one_max import *
from population import *
from individual import *
from mutation.bit_flip_mutation import *
from selection.tournament_selection import *
from recombination.one_point_crossover import *
from problems.single_objective.discrete.binary.one_max import *

from typing import Callable, List, Tuple
from collections.abc import Callable
Expand Down Expand Up @@ -181,7 +225,6 @@ def cga(

mean = sum(ind.fitness_value for ind in pop_list) / len(pop_list)
avg_objectives.append(mean)

generation += 1

return best_ever_solution
Expand Down
10 changes: 5 additions & 5 deletions pycellga/population.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List
from pycellga.individual import *
from pycellga.grid import *
from pycellga.neighborhoods.linear_9 import Linear9
from pycellga.byte_operators import *
from pycellga.problems.abstract_problem import AbstractProblem
from individual import *
from grid import *
from neighborhoods.linear_9 import Linear9
from byte_operators import *
from problems.abstract_problem import AbstractProblem
from enum import Enum


Expand Down
6 changes: 3 additions & 3 deletions pycellga/problems/single_objective/continuous/ackley.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import pi, e, cos, sqrt, exp
from pycellga.problems.abstract_problem import AbstractProblem
from numpy import pi, e, cos, sqrt, exp,power
from problems.abstract_problem import AbstractProblem

class Ackley(AbstractProblem):
"""
Expand Down Expand Up @@ -53,7 +53,7 @@ def evaluate(self, x, out, *args, **kwargs):
out : dict
Dictionary to store the output fitness values.
"""
sum1 = sum(gene ** 2 for gene in x)
sum1 = sum(power(gene,2) for gene in x)
sum2 = sum(cos(2 * pi * gene) for gene in x)

fitness = -20.0 * exp(-0.2 * sqrt(sum1 / self.dimension)) - exp(sum2 / self.dimension) + 20.0 + e
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/bentcigar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw
from typing import List
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numpy import cos, pi
from mpmath import power as pw
from typing import List, Dict, Any
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Bohachevsky(AbstractProblem):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from typing import List
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Chichinadze(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/dropwave.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from numpy import power, cos, sqrt

class Dropwave(AbstractProblem):
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/fms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from numpy import pi, sin
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/griewank.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
import math
from typing import List

Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/holzman.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw
from typing import List

Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/levy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
import math
from mpmath import power as pw
from typing import List
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/matyas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw

class Matyas(AbstractProblem):
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/pow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw
from typing import List, Tuple

Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/powell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw

class Powell(AbstractProblem):
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/rastrigin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import cos, pi
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Rastrigin(AbstractProblem):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw

class Rosenbrock(AbstractProblem):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem
from mpmath import power as pw

class Rothellipsoid(AbstractProblem):
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/schaffer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from mpmath import power as pw
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Schaffer(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/schaffer2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
from numpy import power as pw
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Schaffer2(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/schwefel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from numpy import sin, sqrt
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Schwefel(AbstractProblem):
"""
Expand Down
2 changes: 1 addition & 1 deletion pycellga/problems/single_objective/continuous/sphere.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pycellga.problems.abstract_problem import AbstractProblem
from problems.abstract_problem import AbstractProblem

class Sphere(AbstractProblem):
"""
Expand Down
Loading

0 comments on commit c7aaeb5

Please sign in to comment.