MCPcopy Create free account
hub / github.com/microsoft/Cream / get_crossover

Method get_crossover

AutoFormer/evolution.py:212–240  ·  view source on GitHub ↗
(self, k, crossover_num)

Source from the content-addressed store, hash-verified

210 return res
211
212 def get_crossover(self, k, crossover_num):
213 assert k in self.keep_top_k
214 print('crossover ......')
215 res = []
216 iter = 0
217 max_iters = 10 * crossover_num
218
219 def random_func():
220
221 p1 = random.choice(self.keep_top_k[k])
222 p2 = random.choice(self.keep_top_k[k])
223 max_iters_tmp = 50
224 while len(p1) != len(p2) and max_iters_tmp > 0:
225 max_iters_tmp -= 1
226 p1 = random.choice(self.keep_top_k[k])
227 p2 = random.choice(self.keep_top_k[k])
228 return tuple(random.choice([i, j]) for i, j in zip(p1, p2))
229
230 cand_iter = self.stack_random_cand(random_func)
231 while len(res) < crossover_num and max_iters > 0:
232 max_iters -= 1
233 cand = next(cand_iter)
234 if not self.is_legal(cand):
235 continue
236 res.append(cand)
237 print('crossover {}/{}'.format(len(res), crossover_num))
238
239 print('crossover_num = {}'.format(len(res)))
240 return res
241
242 def search(self):
243 print(

Callers 1

searchMethod · 0.95

Calls 4

stack_random_candMethod · 0.95
is_legalMethod · 0.95
formatMethod · 0.80
printFunction · 0.50

Tested by

no test coverage detected