Skip to content

Commit

Permalink
(#74) Convert relative imports to absolute imports for improved modul…
Browse files Browse the repository at this point in the history
…e compatibility.
  • Loading branch information
SevgiAkten committed Dec 17, 2024
1 parent 9b73997 commit f8f3510
Show file tree
Hide file tree
Showing 147 changed files with 493 additions and 574 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ from mpmath import power as pw
from typing import List

from pycellga.optimizer import cga
from pycellga.recombination import ByteOnePointCrossover
from pycellga.mutation import ByteMutationRandom
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.mutation.byte_mutation_random import ByteMutationRandom
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType


class ExampleProblem(AbstractProblem):

def __init__(self, n_var):
Expand Down
3 changes: 2 additions & 1 deletion docs/pycellga.problems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ Below is an example of how to create a custom optimization problem by inheriting

.. code-block:: python
from pycellga.problems import AbstractProblem
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
from typing import List
import numpy as np
Expand Down
64 changes: 32 additions & 32 deletions docs/usage_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Here’s how we can define this problem in Python using the `ExampleProblem` cla
from typing import List
from pycellga.optimizer import cga
from pycellga.recombination import ByteOnePointCrossover
from pycellga.mutation import ByteMutationRandom
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.mutation.byte_mutation_random import ByteMutationRandom
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
class ExampleProblem(AbstractProblem):
Expand Down Expand Up @@ -83,10 +83,10 @@ The Alpha Cellular Genetic Algorithm optimizes a real-valued problem using Blxal
from typing import List
from pycellga.optimizer import alpha_cga
from pycellga.recombination import BlxalphaCrossover
from pycellga.mutation import FloatUniformMutation
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.recombination.blxalpha_crossover import BlxalphaCrossover
from pycellga.mutation.float_uniform_mutation import FloatUniformMutation
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
Expand Down Expand Up @@ -130,11 +130,10 @@ The Alpha Cellular Genetic Algorithm optimizes a real-valued problem using Blxal
The Compact Cellular Genetic Algorithm optimizes a binary problem where the goal is to maximize the number of `1`s.

.. code-block:: python
from pycellga.optimizer import ccga
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
class ExampleProblem(AbstractProblem):
Expand Down Expand Up @@ -174,8 +173,8 @@ The Machine-Coded Compact Cellular Genetic Algorithm solves real-valued optimiza
import numpy as np
from pycellga.optimizer import mcccga
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
class RealProblem(AbstractProblem):
Expand Down Expand Up @@ -216,10 +215,10 @@ The Synchronous Cellular Genetic Algorithm optimizes a real-valued problem in a
from typing import List
from pycellga.optimizer import sync_cga
from pycellga.recombination import BlxalphaCrossover
from pycellga.mutation import FloatUniformMutation
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.recombination.blxalpha_crossover import BlxalphaCrossover
from pycellga.mutation.float_uniform_mutation import FloatUniformMutation
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType
Expand Down Expand Up @@ -335,7 +334,7 @@ For permutation-based optimization problems, the following option is available:

.. code-block:: python
from problems.single_objective.discrete.permutation.tsp import Tsp
from pycellga.problems.single_objective.discrete.permutation.tsp import Tsp
These built-in problems provide a diverse set of test cases, allowing users to explore `pycellga`'s capabilities across a wide range of optimization challenges. Users can also define custom problems to suit their specific needs.
Expand All @@ -347,8 +346,8 @@ Choose from selection methods:

.. code-block:: python
from selection.tournament_selection import TournamentSelection
from selection.roulette_wheel_selection import RouletteWheelSelection
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.selection.roulette_wheel_selection import RouletteWheelSelection
**Recombination Operators**
Expand Down Expand Up @@ -395,10 +394,11 @@ Optimize a binary problem using tournament selection, one-point crossover, and b
.. code-block:: python
from pycellga.optimizer import cga
from problems.single_objective.discrete.binary.one_max import OneMax
from pycellga.selection import TournamentSelection
from pycellga.recombination import OnePointCrossover
from pycellga.mutation import BitFlipMutation
from pycellga.problems.single_objective.discrete.binary.one_max import OneMax
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.recombination.one_point_crossover import OnePointCrossover
from pycellga.mutation.bit_flip_mutation import BitFlipMutation
result = cga(
n_cols=5,
Expand All @@ -424,10 +424,10 @@ Solve a real-valued optimization problem using Byte One Point Crossover and Byte
.. code-block:: python
from pycellga.optimizer import cga
from problems.single_objective.continuous.ackley import Ackley
from pycellga.selection import RouletteWheelSelection
from pycellga.recombination import ByteOnePointCrossover
from pycellga.mutation import ByteMutation
from pycellga.problems.single_objective.continuous.ackley import Ackley
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.selection.roulette_wheel_selection import RouletteWheelSelection
from pycellga.mutation.byte_mutation import ByteMutation
result = cga(
n_cols=5,
Expand All @@ -452,10 +452,10 @@ Optimize a TSP using permutation encoding, PMX crossover, and swap mutation.
.. code-block:: python
from pycellga.optimizer import cga
from problems.single_objective.discrete.permutation.tsp import Tsp
from pycellga.selection import TournamentSelection
from pycellga.recombination import PMXCrossover
from pycellga.mutation import SwapMutation
from pycellga.problems.single_objective.discrete.permutation.tsp import Tsp
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.recombination.pmx_crossover import PMXCrossover
from pycellga.mutation.swap_mutation import SwapMutation
result = cga(
n_cols=5,
Expand Down
8 changes: 4 additions & 4 deletions paper/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ from mpmath import power as pw
from typing import List

from pycellga.optimizer import cga
from pycellga.recombination import ByteOnePointCrossover
from pycellga.mutation import ByteMutationRandom
from pycellga.selection import TournamentSelection
from pycellga.problems import AbstractProblem
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.mutation.byte_mutation_random import ByteMutationRandom
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType

class ExampleProblem(AbstractProblem):
Expand Down
12 changes: 0 additions & 12 deletions pycellga/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
from . import example
from . import mutation
from . import neighborhoods
from . import problems
from . import recombination
from . import selection
from . import optimizer
from . import population
from . import individual
from . import grid
from . import byte_operators

10 changes: 0 additions & 10 deletions pycellga/example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import optimizer
from individual import GeneType
from . import example_alpha_cga
from . import example_ccga
from . import example_cga
from . import example_mcccga
from . import example_sync_cga
16 changes: 6 additions & 10 deletions pycellga/example/example_alpha_cga.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from numpy import power as pw
from typing import List

from optimizer import alpha_cga
from recombination import BlxalphaCrossover
from mutation import FloatUniformMutation
from selection import TournamentSelection
from problems import AbstractProblem
from common import GeneType
from pycellga.optimizer import alpha_cga
from pycellga.recombination.blxalpha_crossover import BlxalphaCrossover
from pycellga.mutation.float_uniform_mutation import FloatUniformMutation
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType


class ExampleProblem(AbstractProblem):
Expand Down
13 changes: 5 additions & 8 deletions pycellga/example/example_ccga.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from optimizer import ccga
from selection import TournamentSelection
from problems import AbstractProblem
from common import GeneType

from pycellga.optimizer import ccga
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType

class ExampleProblem(AbstractProblem):

Expand Down
15 changes: 6 additions & 9 deletions pycellga/example/example_cga.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from mpmath import power as pw
from typing import List

from optimizer import cga
from recombination import ByteOnePointCrossover
from mutation import ByteMutationRandom
from selection import TournamentSelection
from problems import AbstractProblem
from common import GeneType
from pycellga.optimizer import cga
from pycellga.recombination.byte_one_point_crossover import ByteOnePointCrossover
from pycellga.mutation.byte_mutation_random import ByteMutationRandom
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType

class ExampleProblem(AbstractProblem):

Expand Down
11 changes: 4 additions & 7 deletions pycellga/example/example_mcccga.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import numpy as np

from optimizer import mcccga
from selection import TournamentSelection
from problems import AbstractProblem
from common import GeneType
from pycellga.optimizer import mcccga
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType

class RealProblem(AbstractProblem):

Expand Down
15 changes: 6 additions & 9 deletions pycellga/example/example_sync_cga.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from numpy import power as pw
from typing import List

from optimizer import sync_cga
from recombination import BlxalphaCrossover
from mutation import FloatUniformMutation
from selection import TournamentSelection
from problems import AbstractProblem
from common import GeneType
from pycellga.optimizer import sync_cga
from pycellga.recombination.blxalpha_crossover import BlxalphaCrossover
from pycellga.mutation.float_uniform_mutation import FloatUniformMutation
from pycellga.selection.tournament_selection import TournamentSelection
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType


class ExampleProblem(AbstractProblem):
Expand Down
9 changes: 3 additions & 6 deletions pycellga/individual.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))


from numpy import random
import numpy as np
import random as rd
from problems.abstract_problem import AbstractProblem
from common import GeneType

from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.common import GeneType


class Individual:
Expand Down
21 changes: 0 additions & 21 deletions pycellga/mutation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
from . import bit_flip_mutation
from . import byte_mutation
from . import byte_mutation_random
from . import float_uniform_mutation
from . import insertion_mutation
from . import mutation_operator
from . import shuffle_mutation
from . import swap_mutation
from . import two_opt_mutation

# -------------------------------- mutation -------------------------------- #
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
# -------------------------------------------------------------------------- #
6 changes: 3 additions & 3 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 problems.abstract_problem import AbstractProblem
from mutation.mutation_operator import MutationOperator
from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator

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

from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator

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

from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator

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

from pycellga.individual import *
from pycellga.problems.abstract_problem import AbstractProblem
from pycellga.mutation.mutation_operator import MutationOperator

class FloatUniformMutation(MutationOperator):
"""
Expand Down
Loading

0 comments on commit f8f3510

Please sign in to comment.