Completed
Push — master ( cc7745...279fb5 )
by Grega
19s queued 17s
created

NiaPy.algorithms.other.ts   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

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

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