Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Eyjafjallajokull/gengen
base: 20d4e063f7
...
head fork: Eyjafjallajokull/gengen
compare: 3d4ad0ac12
  • 10 commits
  • 23 files changed
  • 0 commit comments
  • 1 contributor
View
5 .gitignore
@@ -1,6 +1,5 @@
.idea
cache.image
-log*
-population_*
-population/
+build/*log
+build/*population
tmp
View
8 config.yml → build/monaLisa.yml
@@ -2,7 +2,7 @@ main:
populationPath: population/
populationRamPath: population_ram/
baseBlendPath: main.blend
- baseImage: img/monaLista320.jpg
+ baseImage: img/monaLista.jpg
ga:
generations: 800
@@ -13,10 +13,10 @@ ga:
selectionMultiplier: 0.25
# how many genome objects will be mixed in crossover
- crossoverObjectCount: 50
+ crossoverObjectCountMultiplier: 0.25
crossoverAllNew: 0
- mutationObjectCount: 20
+ mutationObjectCountMultiplier: 0.5
mutationPointCount: 3
mutationCoordinateCount: 3
mutationRandomizeMultiplier: 3
@@ -26,7 +26,7 @@ accuracy:
mutationRandomizeMultiplier:
multiplier: 0.5
minimum: 0.1
- mutationObjectCount:
+ mutationObjectCountMultiplier:
multiplier: 0.75
minimum: 1
int: 1
View
0  img/monaLista320.jpg → build/monaLista.jpg
File renamed without changes
View
0  img/cmpOriginaleSmall.png → build/simple1.png
File renamed without changes
View
0  img/cmpOriginaleSmall2.png → build/simple2.png
File renamed without changes
View
41 build/simple2.yml
@@ -0,0 +1,41 @@
+main:
+ populationPath: build/simple2_population/
+ populationRamPath: tmp/simple2_population/
+ baseImage: build/simple2.png
+ baseBlendPath: main.blend
+
+ga:
+ generations: 800
+ populationSize: 20
+ genomeSize: 10
+
+ selectionMultiplier: 0.25
+
+ crossoverObjectCountMultiplier: 0.2
+ crossoverAllNew: 0
+
+ mutationObjectCountMultiplier: 0.1
+ mutationPointCount: 3
+ mutationCoordinateCount: 3
+ mutationRandomizeMultiplier: 4
+
+accuracy:
+ trigger: 40
+# genomeSize:
+# multiplier: 1.05
+# maximum: 100
+# int: 1
+ mutationRandomizeMultiplier:
+ multiplier: 0.9
+ minimum: 0.1
+# mutationObjectCountMultiplier:
+# multiplier: 0.98
+# minimum: 0.1
+# mutationPointCount:
+# multiplier: 0.95
+# minimum: 1
+# int: 1
+# mutationCoordinateCount:
+# multiplier: 0.95
+# minimum: 1
+# int: 1
View
0  img/cmpOriginaleSmall3.png → build/simple3.png
File renamed without changes
View
62 genetics/accuracy.py
@@ -1,47 +1,49 @@
import lib.config as config
import math
+import lib.log as log
class AccuracyParam:
- def __init__(self, name, cfg, realValue):
+ def __init__(self, name, cfg, currentValue):
self.name = name
self.multiplier = cfg['multiplier']
- self.minimum = cfg['minimum']
- self.scaledValue = float(realValue)
- self.realValue = realValue
- if 'int' in cfg:
+ self.minimum = cfg['minimum'] if 'minimum' in cfg else None
+ self.maximum = cfg['maximum'] if 'maximum' in cfg else None
+ self.originalValue = currentValue
+ self.resetToOriginalValue()
+ if 'int' in cfg and cfg['int']==1:
self.cast = lambda x: int(math.ceil(x))
else:
self.cast = float
- self.realIntSteps = False
+
def __repr__(self):
- return self.name+'_'+str(self.realValue)+'_'+str(self.scaledValue)
+ return self.name+'_'+str(self.currentValue)+'_'+str(self.scaledValue)
+
+ def resetToOriginalValue(self):
+ self.scaledValue = float(self.originalValue)
+ self.currentValue = self.originalValue
def getNextValue(self):
- realValue = self.realValue
- scaledValue = self.scaledValue
- if self.realIntSteps:
- while realValue == self.realValue:
- scaledValue *= self.multiplier
- realValue = self.cast(scaledValue)
- else:
- scaledValue *= self.multiplier
- realValue = self.cast(scaledValue)
- return (realValue, scaledValue)
+ scaledValue = self.scaledValue * self.multiplier
+ currentValue = self.cast(scaledValue)
+ return (currentValue, scaledValue)
def canIncrease(self):
- (real, scaled) = self.getNextValue()
- return self.minimum < real
+ (current, _) = self.getNextValue()
+ if self.minimum != None:
+ return self.minimum < current
+ if self.maximum != None:
+ return self.maximum > current
+ return True
def increase(self):
if not self.canIncrease():
return
- (real, scaled) = self.getNextValue()
- self.realValue = real
+ (current, scaled) = self.getNextValue()
+ self.currentValue = current
self.scaledValue = scaled
class AccuracyMachine:
- def __init__(self, log):
- self.log = log
+ def __init__(self):
self.params = []
if 'accuracy' in config.config:
self.genomeGenerationTrigger = config.config['accuracy']['trigger']
@@ -61,11 +63,17 @@ def canIncrease(self):
def increase(self):
for param in self.params:
- old = param.realValue
+ old = param.currentValue
param.increase()
- config.config['ga'][param.name] = param.realValue
- if old != param.realValue:
- self.log.info('changed %s from %s to %s'%(param.name, str(old), str(param.realValue)))
+ config.config['ga'][param.name] = param.currentValue
+ if old != param.currentValue:
+ log.info('changed %s from %s to %s'%(param.name, str(old), str(param.currentValue)))
+ if param.name == 'genomeSize':
+ for param2 in self.params:
+ if param2.name != 'genomeSize':
+ param2.resetToOriginalValue()
+ log.info('genomeSize change triggered resetting of the other params')
+ break
def checkPopulation(self, population):
if population.getBestGenome().generation >= self.genomeGenerationTrigger:
View
44 genetics/genome.py
@@ -1,9 +1,11 @@
+import math
from genetics.fitness import *
from lib.common import *
import pickle
import random
import copy
import lib.config as config
+import lib.log as log
class Genome(object):
fitnessMachine = BaseFitnessMachine
@@ -42,8 +44,12 @@ def createWithCrossover(self, genomeA, genomeB):
def _createWithCrossover(self, genomeA, genomeB):
self.data = copy.deepcopy(genomeA.data)
- for i in random.sample(xrange(0, config.config['ga']['genomeSize']), config.config['ga']['crossoverObjectCount']):
- self.data[i] = copy.deepcopy(genomeB.data[i])
+ genomeSize = len(genomeA.data) if len(genomeA.data) < len(genomeB.data) else len(genomeB.data)
+ crossoverObjectCount = int(math.ceil(genomeSize * config.config['ga']['crossoverObjectCountMultiplier']))
+ log.debug('%s crossover: objects=%d' % (self.serial, crossoverObjectCount))
+ if crossoverObjectCount < genomeSize:
+ for i in random.sample(xrange(0, genomeSize), crossoverObjectCount):
+ self.data[i] = copy.deepcopy(genomeB.data[i])
def mutate(self):
self._mutate()
@@ -68,14 +74,24 @@ def __init__(self, serial=None):
def _create(self):
self.data = []
for i in range(0, config.config['ga']['genomeSize']):
- obj = []
- obj.append([rand(self.meshConstraints[0]), rand(self.meshConstraints[1]), rand(self.meshConstraints[2])])
- obj.append([rand(self.meshConstraints[0]), rand(self.meshConstraints[1]), rand(self.meshConstraints[2])])
+ self.data.append(self._createObject())
+
+ def _createObject(self):
+ obj = []
+ for _ in [0,1,2]:
obj.append([rand(self.meshConstraints[0]), rand(self.meshConstraints[1]), rand(self.meshConstraints[2])])
- self._sortObjectPoints(obj)
- self.data.append(obj)
+ self._sortObjectPoints(obj)
+ return obj
+
+ def _createWithCrossover(self, genomeA, genomeB):
+ super(MeshGenome, self)._createWithCrossover(genomeA, genomeB)
+ if config.config['ga']['genomeSize'] - len(self.data) > 0:
+ for _ in range(0, config.config['ga']['genomeSize']-len(self.data)):
+ self.data.append(self._createObject())
+
def _sortObjectPoints(self, object):
+ """ sort object points clockwise """
object.sort(lambda a, b: cmp(a[0], b[0]))
left = object.pop(0)
object.sort(lambda a, b: -cmp(a[1], b[1]))
@@ -84,10 +100,12 @@ def _sortObjectPoints(self, object):
object.insert(0, left)
def _mutate(self):
- objectCount = config.config['ga']['mutationObjectCount']
+ objectCount = int(math.ceil(config.config['ga']['mutationObjectCountMultiplier'] * config.config['ga']['genomeSize']))
pointCount = config.config['ga']['mutationPointCount']
coordinateCount = config.config['ga']['mutationCoordinateCount']
randomizeMultiplier = config.config['ga']['mutationRandomizeMultiplier']
+ log.debug('%s mutation: objects=%d points=%d coords=%d rand=%f' %
+ (self.serial, objectCount, pointCount, coordinateCount, randomizeMultiplier))
for object in random.sample(xrange(0,len(self.data)), objectCount):
pointsToMutate = random.sample([0,1,2], pointCount)
for point in pointsToMutate:
@@ -103,7 +121,7 @@ def _create(self):
self.data = [ int(random.randrange(0,2)) for i in range(0, config.config['ga']['genomeSize'])]
def _mutate(self):
- for i in random.sample(xrange(0, len(self.data)), config.config['ga']['mutationObjectCount']):
+ for i in random.sample(xrange(0, len(self.data)), config.config['ga']['mutationObjectCountMultiplier']):
self.data[i] = int(randNumber(self.data[i], 2, config.config['ga']['mutationRandomizeMultiplier']))
self.save()
@@ -116,14 +134,14 @@ class MetaGenome(Genome):
'mutationRandomizeMultiplier': (0.1, 0.5, 1, 2),
'generations': (400,),
'selectionMultiplier': (0.25, 0.5),
- 'crossoverObjectCount': (1, 2, 3),
+ 'crossoverObjectCountMultiplier': (0.1, 0.25, 0.5),
'crossoverAllNew': (1,),
- 'mutationObjectCount': (1, 2, 3)
+ 'mutationObjectCountMultiplier': (0.25, 0.5, 0.75)
},
'main': {
- 'populationPath': '/media/dane/dokumenty/Galeria/3d/gen-gen/population_ram/',
+ 'populationPath': '/media/dane/dokumenty/Galeria/3d/gen-gen/build/simple1_population/',
'baseBlendPath': '/media/dane/dokumenty/Galeria/3d/gen-gen/main.blend',
- 'baseImage': '/media/dane/dokumenty/Galeria/3d/gen-gen/cmpOriginaleSmall.png'
+ 'baseImage': '/media/dane/dokumenty/Galeria/3d/gen-gen/build/simple1.png'
}
}
cfg = {
View
43 genetics/population.py
@@ -1,17 +1,13 @@
import glob
from multiprocessing import Pool
from time import time
-from termcolor import colored
import pickle
import random
from genetics.accuracy import AccuracyMachine
from lib.common import do
+import lib.log as log
import lib.config as config
-generation = lambda s: colored(s, 'yellow', attrs=['bold'])
-stage = lambda s: colored(s, 'green', attrs=['bold'])
-info = lambda s: colored(s, 'blue')
-
def _poolFitnessCalculation(params):
(fitnessMachine, genome) = params
try:
@@ -22,15 +18,14 @@ def _poolFitnessCalculation(params):
class Population():
- def __init__(self, genomeType, log):
+ def __init__(self, genomeType):
self.pool = Pool(processes=4, maxtasksperchild=100)
self.generation = 0
self.genomeType = genomeType
self.genomes = []
- self.log = log
self.fitnessMachine = None
# todo: AccuracyMachine should listen for Population events
- self.accuracyMachine = AccuracyMachine(self.log)
+ self.accuracyMachine = AccuracyMachine()
def load(self):
genomeFiles = glob.glob(config.config['main']['populationRamPath'] + '*_genome.obj')
@@ -39,18 +34,20 @@ def load(self):
for file in genomeFiles:
genome = pickle.load(open(file))
self.genomes.append(genome)
+ log.info('loaded %d genomes' % len(self.genomes))
def initialize(self):
- do('rm -f %s* tmp* cache*' % config.config['main']['populationRamPath'])
+ do('rm -f %s/*' % config.config['main']['populationRamPath'])
do('mkdir %s' % config.config['main']['populationPath'])
+ do('echo > %s' % config.config['main']['logPath'])
for i in range(0, config.config['ga']['populationSize']):
genome = self.genomeType()
genome.create()
self.genomes.append(genome)
- self.log.info('created population of %d genomes' % config.config['ga']['populationSize'])
+ log.info('initialized population of %d genomes' % config.config['ga']['populationSize'])
def step(self):
- self.log.info(generation('SUNRISE %d generation' % self.generation))
+ log.info('SUNRISE %d generation' % self.generation)
start = time()
self.calculateFitness()
@@ -60,27 +57,27 @@ def step(self):
self.resetGeneration()
bestGenome = self.genomes[0]
- self.log.debug(
- info('current population ') + ', '.join(map(lambda a: a.serial + '-' + str(a.fitness), self.genomes)))
- self.log.info(info('best genome %s-%d; average fitness %d'
+ log.debug(
+ 'current population ' + ', '.join(map(lambda a: a.serial + '-' + str(a.fitness), self.genomes)))
+ log.info('best genome %s-%d; average fitness %d'
% (bestGenome.serial, bestGenome.fitness,
- reduce(lambda avg, g: avg + g.fitness, self.genomes, 0) / len(self.genomes))))
-
+ reduce(lambda avg, g: avg + g.fitness, self.genomes, 0) / len(self.genomes)))
+ log.debug('genomeSize=%d' % config.config['ga']['genomeSize'])
parents = self.selection()
self.crossover(parents)
- self.log.info(generation('SUNSET %d seconds' % int(time() - start)))
+ log.info('%d s' % int(time() - start))
def calculateFitness(self):
- self.log.debug(info('calculateFitness'))
+ log.debug('calculateFitness')
poolData = [[self.fitnessMachine, g] for g in self.genomes]
timeout = 5 * config.config['ga']['populationSize']*10000
self.genomes = self.pool.map_async(_poolFitnessCalculation, poolData).get(timeout)
def selection(self):
selectedGenomes = self._selectionTournament()
- self.log.debug(stage('selected %d genomes' % (len(selectedGenomes))))
+ log.debug('selected %d genomes' % (len(selectedGenomes)))
selectedGenomes = sorted(selectedGenomes, cmp=lambda a, b: cmp(a.fitness, b.fitness))
- self.log.debug(', '.join(map(lambda a: a.serial + '-' + str(a.fitness), selectedGenomes)))
+ log.debug(', '.join(map(lambda a: a.serial + '-' + str(a.fitness), selectedGenomes)))
return selectedGenomes
def _selectionTournament(self):
@@ -119,9 +116,9 @@ def _selectionTournament(self):
# return selectedGenomes
def crossover(self, parents):
- self.log.debug(stage('crossover'))
+ log.debug('crossover')
if config.config['ga']['crossoverAllNew'] == 1:
- self.log.info('clear population')
+ log.info('clear population')
for genome in self.genomes:
genome.remove()
self.genomes = []
@@ -142,7 +139,7 @@ def getBestGenome(self):
return self.genomes[0]
def resetGeneration(self):
- self.log.info('resetGeneration')
+ log.info('resetGeneration')
self.generation = 0
for genome in self.genomes:
genome.generation = 0
View
25 gengen.py
@@ -1,27 +1,12 @@
import argparse
-import sys
-import logging
from unittest import TestLoader, TextTestRunner
-from lib.config import readConfig
from genetics.population import Population
from genetics.genome import *
from lib.renderer.blender import BlenderRenderer
+from lib.config import readConfig
+from lib.log import initLogger
+
-def initLogger():
- #todo: make logging config global
- rawFormatter = logging.Formatter('%(asctime)s:%(name)s:%(levelname)s %(message)s')
- prettyFormatter = logging.Formatter('%(message)s')
- stdoutHandler = logging.StreamHandler(sys.stdout)
- stdoutHandler.setLevel(logging.INFO)
- stdoutHandler.setFormatter(prettyFormatter)
- fileHandler = logging.FileHandler('log.log')
- fileHandler.setLevel(logging.DEBUG)
- fileHandler.setFormatter(rawFormatter)
- logger = logging.getLogger('population')
- logger.setLevel(logging.DEBUG)
- logger.addHandler(stdoutHandler)
- logger.addHandler(fileHandler)
- return logger
def initRamDir(basePath, ramPath):
tmp = ramPath
@@ -39,7 +24,7 @@ def closeRamDir(basePath, ramPath):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('command', metavar='COMMAND', help='command: init, evolve, tests')
- parser.add_argument('-c','--config', metavar='CONFIG', default='config.yml', help='load alternative config file')
+ parser.add_argument('-c','--config', metavar='CONFIG', help='config file')
#todo: add debug mode
# parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
args = parser.parse_args()
@@ -62,7 +47,7 @@ def closeRamDir(basePath, ramPath):
br = BlenderRenderer()
fm = MeshFitnessMachine(cfg['main']['baseImage'], br)
- p = Population(MeshGenome, logger)
+ p = Population(MeshGenome)
p.fitnessMachine = fm
if args.command=='init':
View
BIN  img/cmpOriginale.png
Deleted file not rendered
View
BIN  img/monaLista320 (kopia).jpg
Deleted file not rendered
View
1  lib/config.py
@@ -5,4 +5,5 @@ def readConfig(path):
global config
config = yaml.load(open(path))
config['main']['configPath'] = path
+ config['main']['logPath'] = path.replace('.yml', '.log')
return config
View
2  lib/image.py
@@ -3,7 +3,6 @@
import numpy
from PIL import Image
-cacheFile = 'tmp/cache.image'
cache = None
processPixelStep = 10
@@ -40,6 +39,7 @@ def compare(original, test):
''' Im mniejsza liczba tym bardziej obrazy sa podobne do siebie '''
global cache
if cache==None:
+ cacheFile = 'tmp' + os.sep + original.replace('/','_') + '.cache'
if os.path.exists(cacheFile):
cache = pickle.load(open(cacheFile))
else:
View
30 lib/log.py
@@ -0,0 +1,30 @@
+import logging
+import sys
+log = None
+import lib.config as config
+
+def initLogger():
+ global log
+ rawFormatter = logging.Formatter('%(asctime)s;%(caller)s;%(levelname)s %(message)s')
+ prettyFormatter = logging.Formatter('%(message)s')
+ stdoutHandler = logging.StreamHandler(sys.stdout)
+ stdoutHandler.setLevel(logging.INFO)
+ stdoutHandler.setFormatter(prettyFormatter)
+ fileHandler = logging.FileHandler(config.config['main']['logPath'])
+ fileHandler.setLevel(logging.DEBUG)
+ fileHandler.setFormatter(rawFormatter)
+ log = logging.getLogger('population')
+ log.setLevel(logging.DEBUG)
+ log.addHandler(stdoutHandler)
+ log.addHandler(fileHandler)
+ return log
+
+def info(msg, *args, **kwargs):
+ kwargs['extra'] = {'caller': sys._getframe(1).f_globals['__name__']}
+ log.info(msg, *args, **kwargs)
+def debug(msg, *args, **kwargs):
+ kwargs['extra'] = {'caller': sys._getframe(1).f_globals['__name__']}
+ log.debug(msg, *args, **kwargs)
+def error(msg, *args, **kwargs):
+ kwargs['extra'] = {'caller': sys._getframe(1).f_globals['__name__']}
+ log.error(msg, *args, **kwargs)
View
15 tests/accuracy.py
@@ -1,15 +0,0 @@
-import logging
-from unittest import TestCase
-from genetics.accuracy import AccuracyMachine
-from lib.config import readConfig
-
-class TestGenome(TestCase):
- def setUp(self):
- self.cfg = readConfig('tests/fixtures/config/basic.yml')
- logger = logging.getLogger('population')
- logger.addHandler(logging.NullHandler())
- self.object = AccuracyMachine(logger)
-
- def tearDown(self):
- self.object.remove()
- #todo: implement tests
View
8 tests/fixtures/config/basic.yml
@@ -2,7 +2,7 @@ main:
populationPath: /media/dane/dokumenty/Galeria/3d/gen-gen/tmp/population_test
populationRamPath: /media/dane/dokumenty/Galeria/3d/gen-gen/tmp/population_test_ram
baseBlendPath: /media/dane/dokumenty/Galeria/3d/gen-gen/main.blend
- baseImage: /media/dane/dokumenty/Galeria/3d/gen-gen/cmpOriginaleSmall2.png
+ baseImage: /media/dane/dokumenty/Galeria/3d/gen-gen/build/simple2.png
ga:
generations: 100
@@ -13,10 +13,10 @@ ga:
selectionMultiplier: 0.25
# ile obiektow genomu zostanie przeszczepionych
- crossoverObjectCount: 1
+ crossoverObjectCountMultiplier: 0.1
crossoverAllNew: 0
- mutationObjectCount: 1
+ mutationObjectCountMultiplier: 0.5
mutationPointCount: 3
mutationCoordinateCount: 3
mutationRandomizeMultiplier: 6
@@ -29,4 +29,4 @@ accuracy:
mutationRandomizeMultiplier:
multiplier: 0.75
minimum: 0.1
- int: True
+ int: 1
View
46 tests/test_accuracy.py
@@ -0,0 +1,46 @@
+import math
+from tests.test_base import TestBase
+from genetics.accuracy import AccuracyMachine, AccuracyParam
+
+class TestAccuracyMachine(TestBase):
+ def setUp(self):
+ self.initConfig('basic')
+ self.initLog()
+ self.object = AccuracyMachine()
+
+class TestAccuracyParam(TestBase):
+ data = {
+ 'float': {
+ 'multiplier': 0.5,
+ 'minimum': 0.1,
+ 'int': 0,
+ 'start': 3
+ },
+ 'int': {
+ 'multiplier': 0.5,
+ 'minimum': 0.1,
+ 'int': 1,
+ 'start': 3
+ }
+ }
+
+ def setUp(self):
+ self.initLog()
+
+ def test_getNextValue(self):
+ for (name, cfg) in self.data.items():
+ object = AccuracyParam(name, cfg, cfg['start'])
+ (real, scaled) = object.getNextValue()
+ if cfg['int'] == 1:
+ self.assertEqual(real, int(math.ceil(cfg['start']*cfg['multiplier'])))
+ else:
+ self.assertEqual(real, cfg['start']*cfg['multiplier'])
+ self.assertEqual(scaled, cfg['start']*cfg['multiplier'])
+
+ def test_limit(self):
+ cfg = self.data['float']
+ object = AccuracyParam('float', cfg, cfg['start'])
+ for _ in range(0,100):
+ object.increase()
+ self.assertGreaterEqual(object.currentValue, cfg['minimum'])
+ self.assertFalse(object.canIncrease())
View
12 tests/test_base.py
@@ -0,0 +1,12 @@
+import logging
+from unittest import TestCase
+from lib.config import readConfig
+import lib.log as log
+
+class TestBase(TestCase):
+ def initConfig(self, name):
+ self.cfg = readConfig('tests/fixtures/config/%s.yml' % name)
+
+ def initLog(self):
+ log.log = logging.getLogger('population')
+ log.log.addHandler(logging.NullHandler())
View
4 tests/common.py → tests/test_common.py
@@ -1,7 +1,7 @@
-from unittest import TestCase
+from tests.test_base import TestBase
from lib.common import randNumber
-class TestRandNumber(TestCase):
+class TestRandNumber(TestBase):
def test_randNumber(self):
arguments = (
(10, 20, 1),
View
13 tests/genome.py → tests/test_genome.py
@@ -1,12 +1,11 @@
import copy
import os
-from unittest import TestCase
+from tests.test_base import TestBase
from genetics.genome import Genome, MeshGenome
-from lib.config import readConfig
-class TestGenome(TestCase):
+class TestGenome(TestBase):
def setUp(self):
- self.cfg = readConfig('tests/fixtures/config/basic.yml')
+ self.initConfig('basic')
self.object = Genome()
def tearDown(self):
@@ -41,9 +40,9 @@ def test_setFitness(self):
self.assertFalse(self.object.dataModified)
self.assertEqual(self.object.fitness, 123)
-class TestMeshGenome(TestCase):
+class TestMeshGenome(TestBase):
def setUp(self):
- self.cfg = readConfig('tests/fixtures/config/basic.yml')
+ self.initConfig('basic')
self.object = MeshGenome()
def tearDown(self):
@@ -76,7 +75,7 @@ def test__mutate(self):
mutatedData = self.object.data
self.assert_data(mutatedData)
- expectedMutatedObjects = self.cfg['ga']['mutationObjectCount']
+ expectedMutatedObjects = self.cfg['ga']['mutationObjectCountMultiplier'] * self.cfg['ga']['genomeSize']
expectedMutatedPoints = self.cfg['ga']['mutationPointCount']
expectedMutatedCoordinates = self.cfg['ga']['mutationCoordinateCount']
mutatedObjects = 0
View
14 tests/population.py → tests/test_population.py
@@ -1,18 +1,14 @@
-import logging
-import unittest
from genetics.population import Population
from genetics.genome import TestGenome
-from lib.config import readConfig
+from tests.test_base import TestBase
-
-class TestPopulation(unittest.TestCase):
+class TestPopulation(TestBase):
genomeType = TestGenome
def setUp(self):
- self.cfg = readConfig('tests/fixtures/config/basic.yml')
- logger = logging.getLogger('population')
- logger.addHandler(logging.NullHandler())
- self.population = Population(self.genomeType, logger)
+ self.initConfig('basic')
+ self.initLog()
+ self.population = Population(self.genomeType)
self.population.pool._processes = 1
def test_load_init(self):

No commit comments for this range

Something went wrong with that request. Please try again.