def _color_minimum_energy_path(self, m1, m2): """find the minimum energy path between m1 and m2 and color the dgraph appropriately""" # add weight attribute to the graph # note: this is not actually the minimum energy path. # This minimizes the sum of energies along the path # TODO: use minimum spanning tree to find the minimum energy path path = minimum_energy_path(self.graph, m1, m2) # emin = min(( m.energy for m in self.graph.nodes_iter() )) # for u, v, data in self.graph.edges_iter(data=True): # data["weight"] = data["ts"].energy - emin # path = nx.shortest_path(self.graph, m1, m2, weight="weight") print("there are", len(path), "minima in the path from", m1._id, "to", m2._id) # color all trees up to the least common ancestor in the dgraph trees = [self.dg.minimum_to_leave[m] for m in path] ancestry = TreeLeastCommonAncestor(trees) all_trees = ancestry.get_all_paths_to_common_ancestor() # remove the least common ancestor so the coloring doesn't go to higher energies all_trees.remove(ancestry.least_common_ancestor) # color the trees for tree in all_trees: tree.data["colour"] = (1., 0., 0.) self.redraw_disconnectivity_graph()
def test(self): t1 = Tree() t2_1 = Tree(t1) t2_2 = Tree(t1) lca = TreeLeastCommonAncestor([t2_1, t2_2]) self.assertEqual(lca.least_common_ancestor, t1) t3_1 = Tree(t2_1) t3_2 = Tree(t2_1) t3_3 = Tree(t2_2) self.assertEqual( TreeLeastCommonAncestor([t3_1, t3_2]).least_common_ancestor, t2_1) self.assertEqual( TreeLeastCommonAncestor([t3_1, t3_2, t3_3]).least_common_ancestor, t1) self.assertEqual( TreeLeastCommonAncestor([t2_1, t3_1]).least_common_ancestor, t2_1) self.assertEqual( TreeLeastCommonAncestor([t2_2, t3_1]).least_common_ancestor, t1) lca = TreeLeastCommonAncestor([t3_1, t3_2]) try: self.assertItemsEqual(lca.get_all_paths_to_common_ancestor(), [t2_1, t3_1, t3_2]) except AttributeError: self.assertCountEqual(lca.get_all_paths_to_common_ancestor(), [t2_1, t3_1, t3_2])
def test(self): t1 = Tree() t2_1 = Tree(t1) t2_2 = Tree(t1) lca = TreeLeastCommonAncestor([t2_1, t2_2]) self.assertEqual(lca.least_common_ancestor, t1) t3_1 = Tree(t2_1) t3_2 = Tree(t2_1) t3_3 = Tree(t2_2) self.assertEqual(TreeLeastCommonAncestor([t3_1, t3_2]).least_common_ancestor, t2_1) self.assertEqual(TreeLeastCommonAncestor([t3_1, t3_2, t3_3]).least_common_ancestor, t1) self.assertEqual(TreeLeastCommonAncestor([t2_1, t3_1]).least_common_ancestor, t2_1) self.assertEqual(TreeLeastCommonAncestor([t2_2, t3_1]).least_common_ancestor, t1) lca = TreeLeastCommonAncestor([t3_1, t3_2]) self.assertItemsEqual(lca.get_all_paths_to_common_ancestor(), [t2_1, t3_1, t3_2])
def _color_minimum_energy_path(self, m1, m2): """find the minimum energy path between m1 and m2 and color the dgraph appropriately""" # add weight attribute to the graph # note: this is not actually the minimum energy path. # This minimizes the sum of energies along the path # TODO: use minimum spanning tree to find the minimum energy path path = minimum_energy_path(self.graph, m1, m2) # emin = min(( m.energy for m in self.graph.nodes_iter() )) # for u, v, data in self.graph.edges_iter(data=True): # data["weight"] = data["ts"].energy - emin # path = nx.shortest_path(self.graph, m1, m2, weight="weight") print "there are", len(path), "minima in the path from", m1._id, "to", m2._id # color all trees up to the least common ancestor in the dgraph trees = [self.dg.minimum_to_leave[m] for m in path] ancestry = TreeLeastCommonAncestor(trees) all_trees = ancestry.get_all_paths_to_common_ancestor() # remove the least common ancestor so the coloring doesn't go to higher energies all_trees.remove(ancestry.least_common_ancestor) # color the trees for tree in all_trees: tree.data["colour"] = (1., 0., 0.) self.redraw_disconnectivity_graph()