def test_cc(termination, seed=None):
    term = termination(mask=seed)
    collapse = ct.collapsed(term(solver, True))
    mask = list(collapse.values())[-1]
    # full results as mask
    _term = termination(mask=mask)
    assert not ct.collapsed(_term(solver, True))
    # update mask with full results
    _term = ma.update_mask(term, collapse)
    assert mask == ma.get_mask(_term)
    assert not ct.collapsed(_term(solver, True))
Exemple #2
0
def test_cc(termination, seed=None):
    term = termination(mask=seed)
    collapse = ct.collapsed(term(solver, True))
    mask = collapse.values()[-1]
    # full results as mask
    _term = termination(mask=mask)
    assert not ct.collapsed(_term(solver, True))
    # update mask with full results
    _term = ma.update_mask(term, collapse)
    assert mask == ma.get_mask(_term)
    assert not ct.collapsed(_term(solver, True))
Exemple #3
0
    def Collapsed(self, disp=False, info=False):
        """check if the solver meets the given collapse conditions

Input::
    - disp: if True, print details about the solver state at collapse
    - info: if True, return collapsed state (instead of boolean)"""
        stop = getattr(self, '__stop__', self.Terminated(info=True))
        import mystic.collapse as ct
        collapses = ct.collapsed(stop) or dict()
        if collapses and disp:
            for (k, v) in getattr(collapses, 'iteritems', collapses.items)():
                print("         %s: %s" % (k.split()[0], v))
        #print("# Collapse at: Generation", self._stepmon._step-1, \
        #      "with", self.bestEnergy, "@\n#", list(self.bestSolution))
        return collapses if info else bool(collapses)
    def Collapsed(self, disp=False, info=False):
        """check if the solver meets the given collapse conditions

Input::
    - disp = if True, print details about the solver state at collapse
    - info = if True, return collapsed state (instead of boolean)
"""
        stop = getattr(self, '__stop__', self.Terminated(info=True))
        import mystic.collapse as ct
        collapses = ct.collapsed(stop) or dict()
        if collapses and disp:
            for (k,v) in getattr(collapses, 'iteritems', collapses.items)():
                print("         %s: %s" % (k.split()[0],v))
           #print("# Collapse at: Generation", self._stepmon._step-1, \
           #      "with", self.bestEnergy, "@\n#", list(self.bestSolution))
        return collapses if info else bool(collapses) 
    # update mask with full results
    _term = ma.update_mask(term, collapse)
    assert mask == ma.get_mask(_term)
    assert not ct.collapsed(_term(solver, True))


for term in (mt.CollapseAt, mt.CollapseAs):
    test_cc(term)

for term in (mt.CollapseWeight, mt.CollapsePosition):
    for seed in (None, {}, set(), ()):
        test_cc(term, seed)

##############################################
stop = mt.Or((mt.ChangeOverGeneration(), \
              mt.CollapseWeight(), \
              mt.CollapsePosition()))

message = stop(solver, True)

_stop = ma.update_mask(stop, ct.collapsed(message))

message = _stop(solver, True)
assert message
collapse = ct.collapsed(message)
assert not collapse
stop_ = ma.update_mask(_stop, collapse)
assert mt.state(stop_) == mt.state(_stop)

# EOF
Exemple #6
0
    _term = ma.update_mask(term, collapse)
    assert mask == ma.get_mask(_term)
    assert not ct.collapsed(_term(solver, True))

for term in (mt.CollapseAt, mt.CollapseAs):
    test_cc(term)

for term in (mt.CollapseWeight, mt.CollapsePosition):
    for seed in (None, {}, set(), ()):
        test_cc(term, seed)

##############################################
stop = mt.Or((mt.ChangeOverGeneration(), \
              mt.CollapseWeight(), \
              mt.CollapsePosition()))

message = stop(solver, True)

_stop = ma.update_mask(stop, ct.collapsed(message))

message = _stop(solver, True)
assert message
collapse = ct.collapsed(message)
assert not collapse
stop_ = ma.update_mask(_stop, collapse)
assert mt.state(stop_) == mt.state(_stop)



# EOF