def _CollapsePosition(inst, info=False): if info: info = lambda x:x else: info = bool hist = inst.energy_history lg = len(hist) if lg <= generations: return info(null) #XXX: might want to log/utilize *where* collapse happens... # if collapse_weight(inst._stepmon, **kwds): return info(doc) collapsed = ct.collapse_position(inst._stepmon, **kwds) if collapsed: return info(doc + ' at %s' % str(collapsed)) # otherwise bail out return info(null)
try: ct.collapse_weight(m, mask={(0,1):[(0,1),(2,0)]}); raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(1,):(1,)}); raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(1,2):(1,2)}); raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(1,0):(1,2)}); raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(0,1):(1,2)}); raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(0,1,2):(0,1,2)}); raise RuntimeError() except ValueError: pass # positions x = ct.collapse_position(m, mask=None) assert x == {0:set(((0,1),)), 1:set(((0,1),(1,2),(0,2)),), 2:set(((1,2),))} x = ct.collapse_position(m, mask={0:set(((0,1),)), 1:set(((1,2),))}) assert x == {1:set(((0,1),(0,2)),), 2:set(((1,2),))} x = ct.collapse_position(m, mask=((0,1,2),((0,1),(1,2),(0,2)))) assert x == ((1,1,2), ((0,1),(0,2),(1,2))) x = ct.collapse_position(m, mask=set(((0,(0,1)),(1,(1,2)),(2,(2,0))))) assert x == set(((1,(0,1)),(1,(0,2)),(2,(1,2)))) try: ct.collapse_position(m, mask=(None,None)); raise RuntimeError() except TypeError: pass try: ct.collapse_position(m, mask=(0,None)); raise RuntimeError() except TypeError: pass try: ct.collapse_position(m, mask=(None,2)); raise RuntimeError() except TypeError: pass try: ct.collapse_position(m, mask=(1,2)); raise RuntimeError() except TypeError: pass
assert not ct.collapse_at(m, target=0.0, mask=ix) ix = ct.collapse_at(m, target=m.x[-1]) assert not ct.collapse_at(m, target=m.x[-1], mask=ix) # print('collapse_as') ix = ct.collapse_as(m) # set([(10, 11), (7, 12), (10, 12), (8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (8, 10), (9, 11), (7, 10), (1, 10), (7, 14), (9, 14), (12, 14), (8, 11), (9, 10), (1, 9), (11, 12), (7, 9), (1, 12), (8, 12), (3, 4), (1, 8), (10, 14), (6, 13), (1, 7), (7, 8), (9, 12)]) assert not ct.collapse_as(m, mask=ix) # print('collapse_weight') ix = ct.collapse_weight(m) # {0: {1}, 1: {1, 2}, 2: {0, 2}} assert not ct.collapse_weight(m, mask=ix) # print('collapse_position') ix = ct.collapse_position(m) # {0: {(0,1)}, 1:{(0,1),(0,2),(1,2)}, 2:{(1,2)}} assert not ct.collapse_position(m, mask=ix) ############################################## # print(mt.CollapseAt()(solver, True)) # print(mt.CollapseAt(target=0.0)(solver, True)) # print(mt.CollapseAs()(solver, True)) # print(mt.CollapseWeight()(solver, True)) # print(mt.CollapseWeight(mask=set())(solver, True)) # print(mt.CollapseWeight(mask=())(solver, True)) # print(mt.CollapsePosition()(solver, True)) # print(mt.CollapsePosition(mask=set())(solver, True)) # print(mt.CollapsePosition(mask=())(solver, True))
raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(0, 1): (1, 2)}) raise RuntimeError() except ValueError: pass try: ct.collapse_weight(m, mask={(0, 1, 2): (0, 1, 2)}) raise RuntimeError() except ValueError: pass # positions x = ct.collapse_position(m, mask=None) assert x == { 0: set(((0, 1), )), 1: set(((0, 1), (1, 2), (0, 2)), ), 2: set(((1, 2), )) } x = ct.collapse_position(m, mask={0: set(((0, 1), )), 1: set(((1, 2), ))}) assert x == {1: set(((0, 1), (0, 2)), ), 2: set(((1, 2), ))} x = ct.collapse_position(m, mask=((0, 1, 2), ((0, 1), (1, 2), (0, 2)))) assert x == ((1, 1, 2), ((0, 1), (0, 2), (1, 2))) x = ct.collapse_position(m, mask=set(((0, (0, 1)), (1, (1, 2)), (2, (2, 0))))) assert x == set(((1, (0, 1)), (1, (0, 2)), (2, (1, 2)))) try: ct.collapse_position(m, mask=(None, None)) raise RuntimeError() except TypeError:
assert not ct.collapse_at(m, target=0.0, mask=ix) ix = ct.collapse_at(m, target=m.x[-1]) assert not ct.collapse_at(m, target=m.x[-1], mask=ix) # print 'collapse_as' ix = ct.collapse_as(m) # set([(10, 11), (7, 12), (10, 12), (8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (8, 10), (9, 11), (7, 10), (1, 10), (7, 14), (9, 14), (12, 14), (8, 11), (9, 10), (1, 9), (11, 12), (7, 9), (1, 12), (8, 12), (3, 4), (1, 8), (10, 14), (6, 13), (1, 7), (7, 8), (9, 12)]) assert not ct.collapse_as(m, mask=ix) # print 'collapse_weight' ix = ct.collapse_weight(m) # {0: {1}, 1: {1, 2}, 2: {0, 2}} assert not ct.collapse_weight(m, mask=ix) # print 'collapse_position' ix = ct.collapse_position(m) # {0: {(0,1)}, 1:{(0,1),(0,2),(1,2)}, 2:{(1,2)}} assert not ct.collapse_position(m, mask=ix) ############################################## # print mt.CollapseAt()(solver, True) # print mt.CollapseAt(target=0.0)(solver, True) # print mt.CollapseAs()(solver, True) # print mt.CollapseWeight()(solver, True) # print mt.CollapseWeight(mask=set())(solver, True) # print mt.CollapseWeight(mask=())(solver, True) # print mt.CollapsePosition()(solver, True) # print mt.CollapsePosition(mask=set())(solver, True) # print mt.CollapsePosition(mask=())(solver, True) def test_cc(termination, seed=None):