Skip to content

Commit cc1ffdd

Browse files
committed
V0.5.7 : refactoring params genetic_operator
1 parent 03e66a0 commit cc1ffdd

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

moead_framework/core/genetic_operator/abstract_operator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
class GeneticOperator(ABC):
55

6-
def __init__(self, solutions, crossover_points=1):
6+
def __init__(self, solutions, **kwargs):
77
self.solutions = solutions
8-
self.crossover_points = crossover_points
98

109
@abstractmethod
1110
def run(self):

moead_framework/core/genetic_operator/combinatorial/cross_mut.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44

55

66
class CrossoverAndMutation(GeneticOperator):
7+
def __init__(self, solutions, **kwargs):
8+
super().__init__(solutions, **kwargs)
9+
if kwargs.get("crossover_points") is None:
10+
self.crossover_points = 1
11+
else:
12+
self.crossover_points = int(kwargs.get("crossover_points"))
13+
14+
if kwargs.get("mutation_probability") is None:
15+
self.mutation_probability = 1
16+
else:
17+
self.mutation_probability = int(kwargs.get("mutation_probability"))
718

819
def run(self):
920
self.number_of_solution_is_correct(n=2)
1021

1122
child = Crossover(solutions=self.solutions, crossover_points=self.crossover_points).run()
12-
child = BinaryMutation(solutions=[child]).run()
23+
child = BinaryMutation(solutions=[child], mutation_probability=self.mutation_probability).run()
1324

1425
return child

moead_framework/core/genetic_operator/combinatorial/crossover.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
class Crossover(GeneticOperator):
77

8+
def __init__(self, solutions, **kwargs):
9+
super().__init__(solutions, **kwargs)
10+
if kwargs.get("crossover_points") is None:
11+
self.crossover_points = 1
12+
else:
13+
self.crossover_points = int(kwargs.get("crossover_points"))
14+
815
def run(self):
916
self.number_of_solution_is_correct(n=2)
1017
solution1 = self.solutions[0]

moead_framework/core/genetic_operator/combinatorial/mutation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
class BinaryMutation(GeneticOperator):
66

7+
def __init__(self, solutions, **kwargs):
8+
super().__init__(solutions, **kwargs)
9+
if kwargs.get("mutation_probability") is None:
10+
self.mutation_probability = 1
11+
else:
12+
self.mutation_probability = int(kwargs.get("mutation_probability"))
13+
714
def run(self):
815

916
self.number_of_solution_is_correct(n=1)
@@ -14,7 +21,7 @@ def run(self):
1421
for i in range(len(solution)):
1522
probability = random.randint(0, n)
1623

17-
if probability < (1 / n):
24+
if probability < (self.mutation_probability / n):
1825
solution[i] = abs(solution[i]-1)
1926

2027
return solution

moead_framework/problem/combinatorial/knapsack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, objective_number, instance_file):
2323
indexes_to_split.append(index_to_split_one * (i+1) + 1)
2424

2525
kps = np.split(np.array(file_content), indexes_to_split)
26-
print(len(kps))
26+
2727
for kp in kps:
2828
# print(kp)
2929
if kp[0] == "=":

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="moead-framework",
8-
version="0.5.6",
8+
version="0.5.7",
99
author="Geoffrey Pruvost",
1010
author_email="geoffrey@pruvost.xyz",
1111
description="MOEA/D Framework in Python 3",

0 commit comments

Comments
 (0)