Example #1
0
    def _CollapseAs(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 ct.collapse_as(inst._stepmon, **kwds): return info(doc)
        collapsed = ct.collapse_as(inst._stepmon, **kwds)
        if collapsed: return info(doc + ' at %s' % str(collapsed))
        # otherwise bail out
        return info(null) 
Example #2
0
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12)])
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12),(13,14,15)]); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=((10,11),(12,13))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(np.array((10,11)),np.array((12,13)))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=set(((10,11),(12,13)))); raise RuntimeError()
except ValueError: pass
try: ct.collapse_at(m, target=0.0, mask={(10,11):(12,13)}); raise RuntimeError()
except TypeError: pass


# as
x = ct.collapse_as(m, tolerance=0.05, mask=None)
assert x == 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)))
x = ct.collapse_as(m, tolerance=0.05, mask=set(((10,11),(7,12),(10,12))))
assert x == set(((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)))
x = ct.collapse_as(m, tolerance=0.05, mask=set((10,12)))
assert x == set(((8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (9, 11), (7, 14), (9, 14), (8, 11), (1, 9), (7, 9), (3, 4), (1, 8), (6, 13), (1, 7), (7, 8)))
x = ct.collapse_as(m, tolerance=0.05, mask=set((10,12,(9,8),(14,11))))
assert x == set(((7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (9, 11), (7, 14), (9, 14), (8, 11), (1, 9), (7, 9), (3, 4), (1, 8), (6, 13), (1, 7), (7, 8)))
try: ct.collapse_as(m, mask=10); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=(10,11)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=(10,11,12,13)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=set(((10,11,12),(14,8,9)))); raise RuntimeError()
except ValueError: pass
Example #3
0
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12)])
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12),(13,14,15)]); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=((10,11),(12,13))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(np.array((10,11)),np.array((12,13)))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=set(((10,11),(12,13)))); raise RuntimeError()
except ValueError: pass
try: ct.collapse_at(m, target=0.0, mask={(10,11):(12,13)}); raise RuntimeError()
except TypeError: pass


# as
x = ct.collapse_as(m, tolerance=0.05, mask=None)
assert x == 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)))
x = ct.collapse_as(m, tolerance=0.05, mask=set(((10,11),(7,12),(10,12))))
assert x == set(((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)))
x = ct.collapse_as(m, tolerance=0.05, mask=set((10,12)))
assert x == set(((8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (9, 11), (7, 14), (9, 14), (8, 11), (1, 9), (7, 9), (3, 4), (1, 8), (6, 13), (1, 7), (7, 8)))
x = ct.collapse_as(m, tolerance=0.05, mask=set((10,12,(9,8),(14,11))))
assert x == set(((7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (9, 11), (7, 14), (9, 14), (8, 11), (1, 9), (7, 9), (3, 4), (1, 8), (6, 13), (1, 7), (7, 8)))
try: ct.collapse_as(m, mask=10); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=(10,11)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=(10,11,12,13)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_as(m, mask=set(((10,11,12),(14,8,9)))); raise RuntimeError()
except ValueError: pass
solver.SetRandomInitialPoints()
solver.SetGenerationMonitor(m)
##############################################

# print('collapse_at')
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))
Example #5
0
solver.SetRandomInitialPoints()
solver.SetGenerationMonitor(m)
##############################################

# print 'collapse_at'
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)