Added monitors and statistics, also made a module with some

specific python stuff in __init__.py
This commit is contained in:
maartenkeijzer 2003-01-10 15:41:17 +00:00
commit ea2e369542
19 changed files with 503 additions and 47 deletions

View file

@ -3,23 +3,42 @@ import unittest
class TestSGA(unittest.TestCase):
def test(self):
evaluate = EvalFunc()
def dotestSGA(self, evaluate):
init = Init(20)
mutate = Mutate()
xover = Crossover()
pop = Pop(50, init)
pop = eoPop(50, init)
for indy in pop: evaluate(indy)
select = eoDetTournamentSelect(3);
cont = eoGenContinue(20);
cont1 = eoGenContinue(20);
cont = eoCheckPoint(cont1)
mon = eoGnuplot1DMonitor()
avg = eoAverageStat()
bst = eoBestFitnessStat()
mon.add(avg)
mon.add(bst)
# add it to the checkpoint
cont.add(avg)
#cont.add(mon)
cont.add(bst)
sga = eoSGA(select, xover, 0.6, mutate, 0.4, evaluate, cont);
sga(pop)
print pop.best()
def testSGA_Max(self):
evaluate = EvalFunc()
self.dotestSGA(evaluate)
def testSGA_Min(self):
evaluate = MinEvalFunc()
self.dotestSGA(evaluate)
if __name__=='__main__':
unittest.main()