Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
###############################################################################
# Version: 1.1
# Last modified on: 3 April, 2016
# Developers: Michael G. Epitropakis
# email: m_(DOT)_epitropakis_(AT)_lancaster_(DOT)_ac_(DOT)_uk
###############################################################################
from cec2013.cec2013 import *
import numpy as np
import sys, getopt
from gtk.keysyms import function
def main():
print 70*"="
# Demonstration of all functions
for i in range(1,21):
# Create function
f = CEC2013(i)
# Create position vectors
x = np.ones( f.get_dimension() )
# Evaluate :-)
value = f.evaluate(x)
print "f", i, "(", x, ") = ", f.evaluate(x)
print 70*"="
# Demonstration of using how_many_goptima function
for i in range(1,21):
# Create function
f = CEC2013(i)
dim = f.get_dimension()
# Create population of position vectors
pop_size = 10
X = np.zeros( (pop_size, dim) )
ub =np.zeros( dim )
lb =np.zeros( dim )
# Get lower, upper bounds
for k in range(dim):
ub[k] = f.get_ubound(k)
lb[k] = f.get_lbound(k)
# Create population within bounds
fitness = np.zeros( pop_size )
for j in range(pop_size):
X[j] = lb + (ub - lb) * np.random.rand( 1 , dim )
fitness[j] = f.evaluate(X[j])
# Calculate how many global optima are in the population
accuracy = 0.001
count, seeds = how_many_goptima(X, f, accuracy)
print "In the current population there exist", count, "global optimizers."
print "Global optimizers:", seeds
print 70*"="
def bounds():
for arg in sys.argv[1]:
print arg
f = CEC2013(2)
dim = f.get_dimension()
# Create population of position vectors
ub =np.zeros( dim )
lb =np.zeros( dim )
# Get lower, upper bounds
for k in range(dim):
ub[k] = f.get_ubound(k)
lb[k] = f.get_lbound(k)
print lb,ub
#python -c 'from demo import bounds(2); print bounds()'
def hello():
return 'Hey'
if __name__ == "__main__":
bounds()