def _CollapseWeight(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_weight(inst._stepmon, **kwds) if collapsed: return info(doc + ' at %s' % str(collapsed)) # otherwise bail out return info(null)
try: ct.collapse_as(m, mask=[(10,11,12,13)]); raise RuntimeError() except TypeError: pass try: ct.collapse_as(m, mask=[(11,12),(14,9)]); raise RuntimeError() except TypeError: pass try: ct.collapse_as(m, mask=(np.array([11,12]),np.array([14,9]))); raise RuntimeError() except TypeError: pass try: ct.collapse_as(m, mask=(np.array([10,11,12]),np.array([14,8,9]))); raise RuntimeError() except TypeError: pass try: ct.collapse_as(m, mask={11:9}); raise RuntimeError() except TypeError: pass try: ct.collapse_as(m, mask={(11,12):(14,9)}); raise RuntimeError() except TypeError: pass # weights x = ct.collapse_weight(m, mask=None) assert x == {0:set((1,)), 1:set((1,2)), 2:set((0,2))} x = ct.collapse_weight(m, mask={0:set((1,)), 1:set((0,1))}) assert x == {1:set((2,)), 2:set((0,2))} x = ct.collapse_weight(m, mask=((0,1),(1,2))) assert x == ((1,2,2),(1,0,2)) x = ct.collapse_weight(m, mask=set(((0,1),(1,2),(2,0)))) assert x == set(((1,1),(2,2))) try: ct.collapse_weight(m, mask=(None,None)); raise RuntimeError() except TypeError: pass try: ct.collapse_weight(m, mask=(0,None)); raise RuntimeError() except TypeError: pass try: ct.collapse_weight(m, mask=(None,2)); raise RuntimeError() except TypeError: pass try: ct.collapse_weight(m, mask=(1,2)); raise RuntimeError() except TypeError: pass
ix = ct.collapse_at(m) # (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17) assert not ct.collapse_at(m, mask=ix) ix = ct.collapse_at(m, target=0.0) # (1, 7, 8, 9, 10, 11, 12, 14) 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))
ix = ct.collapse_at(m) # (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17) assert not ct.collapse_at(m, mask=ix) ix = ct.collapse_at(m, target=0.0) # (1, 7, 8, 9, 10, 11, 12, 14) 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)