def varol_rotem_local(poset, pi, inv, x): # Move i to the left while maintaining pi as a linear extension of poset. # When i can no longer move to the left, do a cyclic shift to put i back to # its starting position. while True: while move(pi, inv, x, LEFT, poset): yield True left_cyclic_shift(pi, inv, inv[x], x) yield False
def gen_all(n, poset): # 0 and n + 1 will be used as the minimum and maximum poset = add_min_max(poset, 0, n + 1) pi = list(range(n + 2)) inv = pi[:] yield pi[1:-1] x = n while x > 1: if move(pi, inv, x, LEFT, poset): yield pi[1:-1] x = n else: left_cyclic_shift(pi, inv, inv[x], x) x -= 1