Esempio n. 1
0
 def __init__(self, evmode='profit', psize=100, maxstep=100, goal=10000):
     assert evmode in evmap
     self.prepare()  #准备argnames,argpool和template_func
     self.argnames = [k for k, v in sorted(self.args.items())
                      ]  #为了方便预定义种子对位置的查找,因为dict是不保序的
     #self.argnames = self.args.keys()
     self.argpool = [v for k, v in sorted(self.args.items())
                     ]  #为了方便预定义种子对位置的查找,因为dict是不保序的
     #print self.argpool
     #self.argpool = self.args.values()
     self.bitgroups = [
         helper.calc_bitnumber(len(sp)) for sp in self.argpool
     ]
     #print self.bitgroups
     self.celler = BCell  #这里只能是BCell
     #print self.argnames
     self.extractor = evmap[evmode]
     self.psize = psize
     self.maxstep = maxstep
     #self.crossover = helper.uniform_crossover   #可能被predefined_population用到
     self.crossover = helper.bitgroups_crossover_factory(
         self.bitgroups, helper.single_point_crossover_g)
     self.reproducer = helper.simple_reproducer_factory(0.85, 0.1)
     self.selector = helper.roulette_wheel_selection_factory(
         self.reproducer.times_of_length)
     self.goal = goal
     self.ev_result = {}
Esempio n. 2
0
 def test_calc_bitnumber(self):
     self.assertEquals(8, helper.calc_bitnumber(129))
     self.assertEquals(7, helper.calc_bitnumber(128))
     self.assertEquals(7, helper.calc_bitnumber(127))
     self.assertEquals(16, helper.calc_bitnumber(65536))
     self.assertEquals(17, helper.calc_bitnumber(65537))
     self.assertEquals(16, helper.calc_bitnumber(65535))
Esempio n. 3
0
 def __init__(self,evmode='profit',psize=100,maxstep=100,goal=10000):
     assert evmode in evmap
     self.prepare()   #准备argnames,argpool和template_func
     self.argnames = [k for k,v in sorted(self.args.items())]    #为了方便预定义种子对位置的查找,因为dict是不保序的
     #self.argnames = self.args.keys()
     self.argpool = [v for k,v in sorted(self.args.items())]     #为了方便预定义种子对位置的查找,因为dict是不保序的   
     #print self.argpool
     #self.argpool = self.args.values()
     self.bitgroups = [ helper.calc_bitnumber(len(sp)) for sp in self.argpool]
     #print self.bitgroups
     self.celler = BCell    #这里只能是BCell
     #print self.argnames
     self.extractor = evmap[evmode]
     self.psize = psize
     self.maxstep = maxstep
     #self.crossover = helper.uniform_crossover   #可能被predefined_population用到
     self.crossover = helper.bitgroups_crossover_factory(self.bitgroups,helper.single_point_crossover_g)
     self.reproducer = helper.simple_reproducer_factory(0.85,0.1)
     self.selector = helper.roulette_wheel_selection_factory(self.reproducer.times_of_length)        
     self.goal = goal
     self.ev_result = {}
Esempio n. 4
0
 def calc_bits(genes_max):
     bits = []
     for uplimit in genes_max:
         bits.append(helper.calc_bitnumber(uplimit))
     return bits
Esempio n. 5
0
 def calc_bits(genes_max):
     bits = []
     for uplimit in genes_max:
         bits.append(helper.calc_bitnumber(uplimit))
     return bits