def save(self, file_name, fmt="auto"): """ overload Graph.save to make output dotfiles pretty. This is entirely cosmetic. """ u = self # add some properties to prettify dot output if fmt is "dot" or fmt is "auto" and file_name.endswith(".dot"): u = GraphView(self) # add shape property according to vertex owners shape = u.new_vertex_property("string") for v in u.vertices(): if u.vp.owner[v] == 1: shape[v] = "box" else: shape[v] = "diamond" u.vp.shape = shape # add label property according to priorities #u.vertex_properties['label'] = u.vertex_properties['priority'] label = u.new_vertex_property("string") for v in u.vertices(): prio = u.vertex_properties['priority'][v] name = u.vertex_index[v] label[v] = "%d (%d)" % (name, prio) u.vp.label = label Graph.save(u, file_name, fmt)
def is_tree(t): # to undirected t = GraphView(t, directed=False) # num nodes = num edges+1 if t.num_vertices() != (t.num_edges() + 1): return False # all nodes have degree > 0 vs = list(map(int, t.vertices())) degs = t.degree_property_map('out').a[vs] if np.all(degs > 0) == 0: return False return True