示例#1
0
 def get_mcst(self, query_elements, lefts):
     """
     Iterator approach of calculating mcst
     """
     _LOGGER.debug('query_elements %s' % str(query_elements))
     _LOGGER.debug('graph %s' % str(self.undirected_graph._graph))
     _LOGGER.debug('lefts %s' % str(lefts))
     fsub = None
     fwt = 65536
     for subtree, wt in calmcst(query_elements, self.undirected_graph._graph):
         if wt < fwt:
             fwt = wt
             fsub = subtree
         else:
             continue
         ##print "reviewing"
         ##print subtree, wt
         root = subtree.root_index
         if root in lefts:
             _LOGGER.debug("swith_root")
             ##print "switch_root"
             subtree.switch_root(lefts)
         ##print "NODESETS", subtree.nodesets()
         sub_span = self._mst[subtree.root_index]\
                 .subtree_including(set(query_elements))
                 #.subtree_including(subtree.nodesets())
         ##print sub_span, "sub_span"
         ##print "sub_span_sum", sub_span.sum_weight()
         if sub_span != None and sub_span.sum_weight() <= fwt:
             #print sub_span, "sub_span"
             fsub = sub_span
             fwt = sub_span.sum_weight()
         root = sub_span.root_index
         subt = self._spanning[root].subtree_including(set(query_elements))
         if subt.get_edges_weight() <= fwt:
             fsub = subt
             fwt = subt.get_edges_weight()
     ##print fsub,"subtree ", fwt, "fwt"
     ##print "end looking"
     return fsub
示例#2
0
GRAPH = (((34, 0.5), (1, 0.5), (18, 0.66666666666666674)), ((0, 0.5),), (), (),
(), (), (), ((26, 0.92914829447227709), (25, 0.92910566467386613), (30,
0.94191442548260162)), (), ((25, 0.79620495290949378), (19,
0.76862178684024085)), (), (), ((25, 0.81683074908636644),), (), (), (),
(), (), ((29, 0.74404197519018456), (0, 0.66666666666666674), (25,
0.76862178684024085)), ((9, 0.76862178684024085), (20,
0.9344311719397087), (30, 0.94130987118031595)), ((19,
0.9344311719397087), (30, 0.9425471665382249)), (), (), (), (), ((18,
0.76862178684024085), (12, 0.81683074908636644), (7,
0.92910566467386613), (9, 0.79620495290949378), (26,
0.85804314990668473)), ((25, 0.85804314990668473), (7,
0.92914829447227709)), (), (), ((18, 0.74404197519018456),), ((20,
0.9425471665382249), (19, 0.94130987118031595), (7,
0.94191442548260162)), (), (), (), ((0, 0.5),), (), (), (), (), (), ())

print calmcst(KEYS, GRAPH)

KEYS = [20, 25]
GRAPH = (((34, 0.5), (1, 0.5), (18, 0.66666666666666674)), ((0, 0.5),),
(), (), (), (), (), ((26, 0.92914829447227709), (25,
0.92910566467386613), (30, 0.94191442548260162)), (), ((25,
0.79620495290949378), (19, 0.76862178684024085)), (), (), ((25,
0.81683074908636644),), (), (), (), (), (), ((29, 0.74404197519018456),
(0, 0.66666666666666674), (25, 0.76862178684024085)), ((9,
0.76862178684024085), (20, 0.9344311719397087), (30,
0.94130987118031595)), ((19, 0.9344311719397087), (30,
0.9425471665382249)), (), (), (), (), ((18, 0.76862178684024085), (12,
0.81683074908636644), (7, 0.92910566467386613), (9,
0.79620495290949378), (26, 0.85804314990668473)), ((25,
0.85804314990668473), (7, 0.92914829447227709)), (), (), ((18,
0.74404197519018456),), ((20, 0.9425471665382249), (19,