def random_walk_rec(current, trace, length, successor_fn):
import numpy.random as random
if length == 0:
return current
else:
sucs = successor_fn(current)
first = random.randint(len(sucs))
now = first
while True:
suc = sucs[now]
try:
assert not np.any([np.all(np.equal(suc, t)) for t in trace])
result = random_walk_rec(suc, [*trace, suc], length-1, successor_fn)
assert result is not None
return result
except AssertionError:
now = (now+1)%len(sucs)
if now == first:
print("B",end="")
return None
else:
continue
评论列表
文章目录