Ticket #13362: trac_13362.patch
File trac_13362.patch, 2.5 KB (added by , 10 years ago) 


sage/graphs/generic_graph.py
# HG changeset patch # User dcoudert <david.coudert@inria.fr> # Date 1344859877 7200 # Node ID 89f41dec6a4b94baf9c7873d26c401c89894c290 # Parent a7ac8594e68b7272faad47cf7b1cc9743e8a414e trac #13362  Fix bug in function _build_flow_graph diff git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
a b 6585 6585 6586 6586 sage: g = Graph() 6587 6587 sage: g.add_edge(0,1) 6588 sage: f = g._build_flow_graph({(0,1):1}, True) 6588 sage: f = g._build_flow_graph({(0,1):1}, True) 6589 6590 The method removes zerocost flow cycles and updates the values accordingly:: 6591 6592 sage: g = digraphs.DeBruijn(2,3) 6593 sage: flow = {('001','010'):1,('010','100'):1,('010','101'):1,('101','010'):1} 6594 sage: flow_graph = g._build_flow_graph(flow,True) 6595 sage: flow_graph.edges() 6596 [('001', '010', 1), ('010', '100', 1)] 6597 sage: flow = {('001','010'):2,('010','101'):3,('101','011'):2,('101','010'):1} 6598 sage: flow_graph = g._build_flow_graph(flow,True) 6599 sage: flow_graph.edges() 6600 [('001', '010', 2), ('010', '101', 2), ('101', '011', 2)] 6601 6602 Isolated zerocost flow cycles are also removed:: 6603 6604 sage: g = digraphs.DeBruijn(2,3) 6605 sage: flow = {('000','001'):1,('010','101'):1,('101','010'):1} 6606 sage: flow_graph = g._build_flow_graph(flow,True) 6607 sage: flow_graph.edges() 6608 [('000', '001', 1)] 6589 6609 """ 6590 6610 6591 6611 from sage.graphs.digraph import DiGraph … … 6621 6641 if l == 0: 6622 6642 g.delete_edge(sp[i],sp[i+1]) 6623 6643 else: 6624 g.set_edge_label( l)6644 g.set_edge_label(sp[i],sp[i+1],l) 6625 6645 6626 6646 # if integer is set, round values and deletes zeroes 6627 6647 if integer: … … 6629 6649 if l<.5: 6630 6650 g.delete_edge(u,v) 6631 6651 else: 6632 g.set_edge_label(u,v, round(l))6633 6634 # returning a graph with the same embedding, the cor ersponding name, etc ...6652 g.set_edge_label(u,v, int(round(l))) 6653 6654 # returning a graph with the same embedding, the corresponding name, etc ... 6635 6655 h = self.subgraph(edges=[]) 6636 6656 h.delete_vertices([v for v in self if (v not in g) or g.degree(v)==0]) 6637 6657 h.add_edges(g.edges())