Passed
Pull Request — master (#233)
by Grega
01:17
created

NiaPy.algorithms.other.ts   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TabuSearch.move() 0 1 1
A TabuSearch.setParameters() 0 3 1
A TabuSearch.runIteration() 0 15 1
A TabuSearch.typeParameters() 0 3 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A TabuSearchF() 0 10 2
1
# encoding=utf8
2
# pylint: disable=mixed-indentation, trailing-whitespace, multiple-statements, attribute-defined-outside-init, logging-not-lazy, unused-argument, arguments-differ, bad-continuation, singleton-comparison, no-self-use, unused-variable
3
import logging
4
from numpy import random as rand
5
from NiaPy.algorithms.algorithm import Algorithm
6
7
logging.basicConfig()
8
logger = logging.getLogger('NiaPy.algorithms.other')
9
logger.setLevel('INFO')
10
11
__all__ = ['TabuSearch']
12
13
# TODO implement algorithm
14
15
def TabuSearchF(task, SR=None, TL_size=25, rnd=rand):
16
	if SR == None: SR = task.bRange
17
	x = rnd.uniform(task.Lower, task.Upper)
18
	x_f = task.eval(x)
19
	# while not task.stopCondI():
20
	# Generate neigours
21
	# evaluate x not in ts
22
	# get best of of evaluated
23
	# compare new best with best
24
	return x, x_f
25
26
class TabuSearch(Algorithm):
27
	r"""Implementation of Tabu Search Algorithm.
28
29
	Algorithm:
30
		Tabu Search Algorithm
31
32
	Date:
33
		2018
34
35
	Authors:
36
		Klemen Berkovič
37
38
	License:
39
		MIT
40
41
	Reference URL:
42
		http://www.cleveralgorithms.com/nature-inspired/stochastic/tabu_search.html
43
44
	Reference paper:
45
46
	Attributes:
47
		Name (List[str]): List of strings representing algorithm name.
48
	"""
49
	Name = ['TabuSearch', 'TS']
50
51
	@staticmethod
52
	def typeParameters(): return {
53
			'NP': lambda x: isinstance(x, int) and x > 0
54
	}
55
56
	def setParameters(self, **ukwargs):
57
		r"""Set the algorithm parameters/arguments."""
58
		Algorithm.setParameters(self, **ukwargs)
59
60
	def move(self): return list()
61
62
	def runIteration(self, task, pop, fpop, xb, fxb, **dparams):
63
		r"""Core function of the algorithm.
64
65
		Args:
66
			task (Task): Optimization task.
67
			pop (numpy.ndarray): Current population.
68
			fpop (numpy.ndarray): Individuals fitness/objective values.
69
			xb (numpy.ndarray): Global best solution.
70
			fxb (float): Global best solutions fitness/objective value.
71
			**dparams (dict):
72
73
		Returns:
74
			Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, float, dict]:
75
		"""
76
		return pop, fpop, xb, fxb, dparams
77
78
# vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3
79