Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 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