示例#1
0
 def combine(self, s1, s2):
     sn = Solution()
     sn.length_function = copy.deepcopy(s1.length_function) if random() > 0.5 else copy.deepcopy(s2.length_function)
     sn.radiance_function = copy.deepcopy(s1.radiance_function) if random() > 0.5 else copy.deepcopy(s2.radiance_function)
     sn.orientation_function = copy.deepcopy(s1.orientation_function) if random() > 0.5 else copy.deepcopy(s2.orientation_function)
     sn.termination_function = copy.deepcopy(s1.termination_function) if random() > 0.5 else copy.deepcopy(s2.termination_function)
     return sn
示例#2
0
 def new_solution(self):
     def random_term():
         return createTerm('Random', innerMultiplier=uniform(-2.0, 2.0), outerMultiplier=uniform(-3.0, 3.0))
     s = Solution()
     s.length_function = Expression(init_terms=[random_term()])
     s.radiance_function = Expression(init_terms=[random_term()])
     s.orientation_function = Expression(init_terms=[random_term()])
     s.termination_function = Expression(init_terms=[random_term()])
     return s
示例#3
0
    def __init__(self):
        self.fittest = None

        self.generation = 0
        initial_solution = Solution()
        initial_solution.length_function = Expression(init_terms=[createTerm('Constant', innerMultiplier=3.0, outerMultiplier=3.0)])
        initial_solution.radiance_function = Expression(init_terms=[createTerm('Constant', innerMultiplier=1.0, outerMultiplier=1.5)])
        initial_solution.orientation_function = Expression(init_terms=[createTerm('Constant', innerMultiplier=-0.1, outerMultiplier=0.1)])
        initial_solution.termination_function = Expression(init_terms=[createTerm('Constant', innerMultiplier=3.0, outerMultiplier=3.0)])

        self.solutions = [initial_solution]
        workers = cfg.getint('FitnessTest', 'workers')
        if workers > 1:
            print "Evaluating using {workers} worker threads".format(workers=workers)
            self.map = Pool(processes=workers).map_async
        else:
            self.map = map
        self.max_fitness_acheived = 0