Code Duplication    Length = 25-30 lines in 4 locations

NiaPy/algorithms/basic/ga.py 1 location

@@ 19-48 (lines=30) @@
16
        self.generateSolution()
17
18
    def generateSolution(self):
19
        self.Solution = [self.LB + (self.UB - self.LB) * rnd.random()
20
                         for _i in range(self.D)]
21
22
    def evaluate(self):
23
        self.Fitness = Chromosome.FuncEval(self.D, self.Solution)
24
25
    def repair(self):
26
        for i in range(self.D):
27
            if self.Solution[i] > self.UB:
28
                self.Solution[i] = self.UB
29
            if self.Solution[i] < self.LB:
30
                self.Solution[i] = self.LB
31
32
    def __eq__(self, other):
33
        return self.Solution == other.Solution and self.Fitness == other.Fitness
34
35
    def toString(self):
36
        print([i for i in self.Solution])
37
38
39
class GeneticAlgorithm(object):
40
    """Genetic algorithm - BUG is somewhere in code.
41
42
    Date: 12. 2. 2018
43
44
    Authors : Uros Mlakar
45
46
    License: MIT
47
48
    Reference paper: TODO.
49
50
    """
51

NiaPy/algorithms/modified/jde.py 1 location

@@ 22-48 (lines=27) @@
19
        self.Solution = [self.LB + (self.UB - self.LB) * rnd.random()
20
                         for _i in range(self.D)]
21
22
    def evaluate(self):
23
        self.Fitness = SolutionjDE.FuncEval(self.D, self.Solution)
24
25
    def repair(self):
26
        for i in range(self.D):
27
            if self.Solution[i] > self.UB:
28
                self.Solution[i] = self.UB
29
            if self.Solution[i] < self.LB:
30
                self.Solution[i] = self.LB
31
32
    def __eq__(self, other):
33
        return self.Solution == other.Solution and self.Fitness == other.Fitness
34
35
36
class SelfAdaptiveDifferentialEvolutionAlgorithm(object):
37
    """Self-adaptive differential evolution algorithm.
38
39
    Date: 7. 2. 2018
40
41
    Authors : Uros Mlakar
42
43
    License: MIT
44
45
    Reference paper: Brest, J., Greiner, S., Boskovic, B., Mernik, M., Zumer, V. Self-adapting control
46
    parameters in differential evolution: A comparative study on numerical benchmark problems.
47
    IEEE transactions on evolutionary computation, 10(6), 646-657, 2006.
48
49
    TODO
50
    """
51

NiaPy/algorithms/basic/de.py 1 location

@@ 21-45 (lines=25) @@
18
    def generateSolution(self):
19
        self.Solution = [self.LB + (self.UB - self.LB) * rnd.random() for _i in range(self.D)]
20
21
    def evaluate(self):
22
        self.Fitness = SolutionDE.FuncEval(self.D, self.Solution)
23
24
    def repair(self):
25
        for i in range(self.D):
26
            if self.Solution[i] > self.UB:
27
                self.Solution[i] = self.UB
28
            if self.Solution[i] < self.LB:
29
                self.Solution[i] = self.LB
30
31
    def __eq__(self, other):
32
        return self.Solution == other.Solution and self.Fitness == other.Fitness
33
34
35
class DifferentialEvolutionAlgorithm(object):
36
    """Differential evolution algorithm.
37
38
    Date: 7. 2. 2018
39
40
    Authors : Uros Mlakar
41
42
    License: MIT
43
44
    Reference paper: Storn, Rainer, and Kenneth Price. "Differential evolution - a simple and
45
    efficient heuristic for global optimization over continuous spaces." Journal of global
46
    optimization 11.4 (1997): 341-359.
47
    """
48

NiaPy/algorithms/basic/abc.py 1 location

@@ 25-51 (lines=27) @@
22
    def repair(self):
23
        for i in range(self.D):
24
            if self.Solution[i] > self.UB:
25
                self.Solution[i] = self.UB
26
27
            if self.Solution[i] < self.LB:
28
                self.Solution[i] = self.LB
29
30
    def evaluate(self):
31
        self.Fitness = SolutionABC.FuncEval(self.D, self.Solution)
32
33
    def toString(self):
34
        pass
35
36
37
class ArtificialBeeColonyAlgorithm(object):
38
    """Artificial Bee Colony algorithm.
39
40
    Date: 12. 2. 2018
41
42
    Authors : Uros Mlakar
43
44
    License: MIT
45
46
    Reference paper: Karaboga, D., and Bahriye B. "A powerful
47
    and efficient algorithm for numerical function optimization: artificial
48
    bee colony (ABC) algorithm." Journal of global optimization 39.3 (2007): 459-471.
49
50
    EDITED - TODO: More tests are required! Validation!
51
52
    TODO: EVALUATIONS!
53
    """
54