-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.py
108 lines (82 loc) · 2.43 KB
/
test.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/python
# coding=utf-8
#
# General test script of the whole QOpt framework
#
import sys, os
import qopt.algorithms
import qopt.problems
import pylab
############
# Problems #
############
# knapsack
knapsack = qopt.problems.knapsack250
print knapsack.evaluate('1' * 250)
# func 1d
f1d = qopt.problems.func1d.f1
print f1d.evaluate2(60.488)
# sat
import qopt.problems._sat
s1 = qopt.problems._sat.SatProblem('problems/sat/flat30-100.cnf')
print s1.evaluate('100100001100100100001100010100010001010010100010100010010010010010001001001100001001001001')
# cec2005
f1 = qopt.problems.CEC2005(1)
print f1.evaluate((0,0))
f1 = qopt.problems.CEC2013(8)
print f1.evaluate(qopt.problems.CEC2013.optimum[:2])
# cec2011
cassini = qopt.problems.CEC2011(15) # XXX
print cassini.evaluate([-779.629801566988, 3.265804135361, 0.528440291493, 0.382390419772,\
167.937610148996, 424.032204472497, 53.304869390732, 589.767895836123, 2199.961911685212,\
0.772877728290, 0.531757418755, 0.010789195916, 0.167388829033, 0.010425709182,\
1.358596310427, 1.050001151443, 1.306852313623, 69.813404643644, -1.593310577644,\
-1.959572311812, -1.554796022348, -1.513432303179])
# should be 8.383...
# cec2013
f1 = qopt.problems.CEC2013(fnum = 1)
print f1.evaluate(qopt.problems.CEC2013.optimum)
f2 = qopt.problems.CEC2013(fnum = 2)
print f2.evaluate(qopt.problems.CEC2013.optimum)
##############################
# Combinatorial optimization #
##############################
class QIGA(qopt.algorithms.QIGA):
def initialize(self):
super(QIGA, self).initialize()
print 'my initialization'
print self.Q
def generation(self):
super(QIGA, self).generation()
if self.t == 5:
print 'generation %d, bestval: %g' % (self.t, self.bestval)
q = QIGA(chromlen = 250)
q.tmax = 500
q.problem = qopt.problems.knapsack250
import time
t1 = time.time()
for run in xrange(1):
q.run()
print '100 runs in: %g seconds' % (time.time() - t1)
q.run()
#print q.best
print q.bestval
#print q.P[0]
#print q.Q[3,5]
#r = qopt.algorithms.rQIEA()
print 'OK'
sys.exit(0)
q._initialize()
print q.Q
########################################
# Real-Coded -- numerical optimization #
########################################
# cec2005
r = qopt.algorithms.RQIEA
r.problem = qopt.problems.CEC2005(2)
r.dim = 30
r.bounds = None # ??? set automatically in .problem ?
r.run()
# cec2011
r.problem = qopt.problems.CEC2011(15)
r.run()