Beispiel #1
0
class Interpretation(Search):
    def __init__(self, func):
        self.func = func
        self.domain = func.domain()
        assert self.domain, (func, self.domain)
        searches = [Search(iter, func.range()) for element in self.domain]
        self.search = MultiSearch(searches)
        func.map = self.map = {}
        self.reset()

    def reset(self):
        self.search.reset()
        self.map.clear()

    def next(self):
        values = self.search.next()
        for idx, value in enumerate(values):
            self.map[self.domain[idx]] = value
        # return None # not used..

    def __repr__(self):
        return "Interpretation(%s, %s)" % (self.func, self.map)

    def __str__(self):
        if len(self.func.sorts) == 0:
            return nullopstr(self.func.name, self.map)
        elif len(self.func.sorts) == 1:
            return unopstr(self.func.name, self.map)
        elif len(self.func.sorts) == 2:
            return binopstr(self.func.name, self.map)
        else:
            return repr(self)
Beispiel #2
0
 def __init__(self, func):
     self.func = func
     self.domain = func.domain()
     assert self.domain, (func, self.domain)
     searches = [Search(iter, func.range()) for element in self.domain]
     self.search = MultiSearch(searches)
     func.map = self.map = {}
     self.reset()
Beispiel #3
0
    def test_long(self):
        def on_result(result):
            self.assertEqual(len(result), 20)

        ms = MultiSearch(searcher=BacktrackQueens, size=20)
        ms.search(callback=on_result)
        ms.join()