| Total Complexity | 3 |
| Total Lines | 41 |
| Duplicated Lines | 31.71 % |
| Changes | 0 | ||
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 | # This is temporary fix to import module from parent folder |
||
| 3 | # It will be removed when package is published on PyPI |
||
| 4 | import sys |
||
| 5 | sys.path.append('../') |
||
| 6 | # End of fix |
||
| 7 | |||
| 8 | import random |
||
| 9 | import logging |
||
| 10 | |||
| 11 | from NiaPy.algorithms.basic import BareBonesFireworksAlgorithm |
||
| 12 | from NiaPy.benchmarks import Benchmark, Katsuura, Elliptic |
||
| 13 | from NiaPy.task import StoppingTask |
||
| 14 | |||
| 15 | logging.basicConfig() |
||
| 16 | logger = logging.getLogger('examples') |
||
| 17 | logger.setLevel('INFO') |
||
| 18 | |||
| 19 | View Code Duplication | class MyBenchmark(Benchmark): |
|
|
|
|||
| 20 | Name = ['MyBenchmark'] |
||
| 21 | |||
| 22 | def __init__(self): |
||
| 23 | self.Lower = -11 |
||
| 24 | self.Upper = 11 |
||
| 25 | |||
| 26 | def function(self): |
||
| 27 | def evaluate(D, sol): |
||
| 28 | val = 0.0 |
||
| 29 | for i in range(D): val += sol[i] ** 2 |
||
| 30 | return val |
||
| 31 | return evaluate |
||
| 32 | |||
| 33 | benc = MyBenchmark() |
||
| 34 | benc.plot3d() |
||
| 35 | |||
| 36 | benc = Katsuura(-1, 1) |
||
| 37 | benc.plot3d(0.06) |
||
| 38 | |||
| 39 | benc = Elliptic() |
||
| 40 | benc.plot3d(0.65) |
||
| 41 | |||
| 43 |