예제 #1
0
파일: minimize.py 프로젝트: dornja/goa2
    def get_fitness( self, deltas ):
        global cache
        key = self.builder.key( deltas )
        if key in cache:
            fitness, duration = cache[ key ]
            self.duration += duration
            return fitness

        fitness = list()
        start = time.time()
        try:
            with self.builder.build( deltas ) as exe:
                if exe is None:
                    return fitness
                def tester():
                    for line in self.genprog.run_test( exe ):
                        infomsg( "   ", *line, sep = "\t" )
                        yield line
                fitness = list()
                for values in reduce_error( tester, options.low_error, 20 ):
                    if np.any( values == 0 ):
                        fitness = [ np.zeros( len( values ) ) ]
                        break
                    fitness.append( values )
                return fitness
        finally:
            duration = time.time() - start
            self.duration += duration
            if not options.disable_cache:
                cache[ key ] = fitness, duration
예제 #2
0
파일: minimize.py 프로젝트: artintal/goa2
 def get_fitness( self, deltas ):
     global cache
     key = self.builder.key( deltas )
     if key in cache:
         return cache[ key ]
     with self.builder.build( deltas ) as exe:
         if exe is None:
             cache[ key ] = list()
             return list()
         def tester():
             fitness = self.genprog.run_test( exe )
             infomsg( "   ", fitness )
             return fitness
         fitness = list( reduce_error( tester, options.low_error, 20 ) )
         cache[ key ] = fitness
         return fitness