def genNextCand(self, preItems):
     """
     Generate next candidates by dynamic programming
     Find range [i, j) such that items in this range have same prefix
     e.g., [1,2,3,4] and [1,2,3,5] have same prefix, so they should be in one same range
     Then, generate 2-combinations of these ranges as result
     """
     res = []
     i, j = 0, 0
     while i < len(preItems):
         if j < len(preItems) and sameNodes(preItems[j][:-1], preItems[i][:-1]):
             j += 1
         else:
             res += [pair[0] + [pair[1][-1]] for pair in itertools.combinations(preItems[i:j], 2)]
             i = j
     return map(lambda items: map(lambda i: i.name, items), res)
Exemple #2
0
 def genNextCand(self, preItems):
     """
     Generate next candidates by dynamic programming
     Find range [i, j) such that items in this range have same prefix
     e.g., [1,2,3,4] and [1,2,3,5] have same prefix, so they should be in one same range
     Then, generate 2-combinations of these ranges as result
     """
     res = []
     i, j = 0, 0
     while i < len(preItems):
         if j < len(preItems) and sameNodes(preItems[j][:-1],
                                            preItems[i][:-1]):
             j += 1
         else:
             res += [
                 pair[0] + [pair[1][-1]]
                 for pair in itertools.combinations(preItems[i:j], 2)
             ]
             i = j
     return [[i.name for i in items] for items in res]