示例#1
0
 def get_steiner(self, query_elements, lefts):
     """
     dynamic programming for steiner tree problem
     """
     subpaths, root = steiner(self.undirected_graph._graph, query_elements, \
             self.undirected_graph.d, \
             self.undirected_graph.PT)
     n = len(self.undirected_graph._graph)
     lk_set = set([])
     for lk in subpaths:
         ll, rr = lk
         lk_set.add(lk)
         if (rr, ll) in lk_set:
             lk_set.remove(lk)
     sub_span = [[] for _ in self.undirected_graph._graph ]
     for i, j in lk_set:
         sub_span[i].append((j, 0))
         sub_span[j].append((i, 0))
     subtree = RootedWGraph(sub_span, root)
     root = subtree.root_index
     if root in lefts:
         _LOGGER.debug("swith_root")
         subtree.switch_root(lefts)
     return subtree