Passed
Pull Request — master (#233)
by Grega
11:33
created

NiaPy.algorithms.modified.sade   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 125
Duplicated Lines 84.8 %

Importance

Changes 0
Metric Value
wmc 8
eloc 34
dl 106
loc 125
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A StrategyAdaptationDifferentialEvolution.algorithmInfo() 11 11 1
A StrategyAdaptationDifferentialEvolutionV1.algorithmInfo() 11 11 1
A StrategyAdaptationDifferentialEvolution.setParameters() 2 2 1
A StrategyAdaptationDifferentialEvolutionV1.runIteration() 3 3 1
A StrategyAdaptationDifferentialEvolutionV1.getParameters() 4 4 1
A StrategyAdaptationDifferentialEvolution.runIteration() 3 3 1
A StrategyAdaptationDifferentialEvolution.getParameters() 4 4 1
A StrategyAdaptationDifferentialEvolutionV1.setParameters() 2 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
# encoding=utf8
2
import logging
3
4
# from numpy import random as rand, argmin, argmax, mean, asarray, cos
5
6
# from NiaPy.algorithms.algorithm import Individual
7
from NiaPy.algorithms.basic.de import DifferentialEvolution  # , CrossBest1, CrossRand1, CrossCurr2Best1, CrossBest2, CrossCurr2Rand1, proportional
8
9
logging.basicConfig()
10
logger = logging.getLogger('NiaPy.algorithms.modified')
11
logger.setLevel('INFO')
12
13
__all__ = [
14
	'StrategyAdaptationDifferentialEvolution',
15
	'StrategyAdaptationDifferentialEvolutionV1'
16
]
17
18 View Code Duplication
class StrategyAdaptationDifferentialEvolution(DifferentialEvolution):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
19
	r"""Implementation of Differential Evolution Algorithm With Strategy Adaptation algorihtm.
20
21
	Algorithm:
22
		Differential Evolution Algorithm With StrategyAdaptation
23
24
	Date:
25
		2019
26
27
	Author:
28
		Klemen Berkovič
29
30
	License:
31
		MIT
32
33
	Reference URL:
34
		https://ieeexplore.ieee.org/document/1554904
35
36
	Reference paper:
37
		Qin, A. Kai, and Ponnuthurai N. Suganthan. "Self-adaptive differential evolution algorithm for numerical optimization." 2005 IEEE congress on evolutionary computation. Vol. 2. IEEE, 2005.
38
39
	Attributes:
40
		Name (List[str]): List of strings representing algorithm name.
41
42
	See Also:
43
		:class:`NiaPy.algorithms.basic.DifferentialEvolution`
44
	"""
45
	Name = ['StrategyAdaptationDifferentialEvolution', 'SADE', 'SaDE']
46
47
	@staticmethod
48
	def algorithmInfo():
49
		r"""Geg basic algorithm information.
50
51
		Returns:
52
			str: Basic algorithm information.
53
54
		See Also:
55
			:func:`NiaPy.algorithms.algorithm.Algorithm.algorithmInfo`
56
		"""
57
		return r"""Qin, A. Kai, and Ponnuthurai N. Suganthan. "Self-adaptive differential evolution algorithm for numerical optimization." 2005 IEEE congress on evolutionary computation. Vol. 2. IEEE, 2005."""
58
59
	def setParameters(self, **kwargs):
60
		DifferentialEvolution.setParameters(self, **kwargs)
61
		# TODO add parameters of the algorithm
62
63
	def getParameters(self):
64
		d = DifferentialEvolution.getParameters(self)
65
		# TODO add paramters values
66
		return d
67
68
	def runIteration(self, task, pop, fpop, xb, fxb, **dparams):
69
		# TODO implemnt algorithm
70
		return pop, fpop, xb, fxb, dparams
71
72 View Code Duplication
class StrategyAdaptationDifferentialEvolutionV1(DifferentialEvolution):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
73
	r"""Implementation of Differential Evolution Algorithm With Strategy Adaptation algorihtm.
74
75
	Algorithm:
76
		Differential Evolution Algorithm With StrategyAdaptation
77
78
	Date:
79
		2019
80
81
	Author:
82
		Klemen Berkovič
83
84
	License:
85
		MIT
86
87
	Reference URL:
88
		https://ieeexplore.ieee.org/document/4632146
89
90
	Reference paper:
91
		Qin, A. Kai, Vicky Ling Huang, and Ponnuthurai N. Suganthan. "Differential evolution algorithm with strategy adaptation for global numerical optimization." IEEE transactions on Evolutionary Computation 13.2 (2009): 398-417.
92
93
	Attributes:
94
		Name (List[str]): List of strings representing algorithm name.
95
96
	See Also:
97
		:class:`NiaPy.algorithms.basic.DifferentialEvolution`
98
	"""
99
	Name = ['StrategyAdaptationDifferentialEvolutionV1', 'SADEV1', 'SaDEV1']
100
101
	@staticmethod
102
	def algorithmInfo():
103
		r"""Get algorithm information.
104
105
		Returns:
106
			str: Get algorithm information.
107
108
		See Also:
109
			:func:`NiaPy.algorithms.algorithm.Algorithm.algorithmInfo`
110
		"""
111
		return r"""Qin, A. Kai, Vicky Ling Huang, and Ponnuthurai N. Suganthan. "Differential evolution algorithm with strategy adaptation for global numerical optimization." IEEE transactions on Evolutionary Computation 13.2 (2009): 398-417."""
112
113
	def setParameters(self, **kwargs):
114
		DifferentialEvolution.setParameters(self, **kwargs)
115
		# TODO add parameters of the algorithm
116
117
	def getParameters(self):
118
		d = DifferentialEvolution.getParameters(self)
119
		# TODO add paramters values
120
		return d
121
122
	def runIteration(self, task, pop, fpop, xb, fxb, **dparams):
123
		# TODO implement algorithm
124
		return pop, fpop, xb, fxb, dparams
125
126
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
127