# Ticket #8284: trac_8284.patch

File trac_8284.patch, 5.3 KB (added by ncohen, 12 years ago)
• ## sage/graphs/generic_graph.py

# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1275999583 -7200
# Node ID 1f6e22e68ddb753517cb9ad54ee58fa3e9de8423
# Parent  556bb66e4c6dbb92a4ee37c1750d82a5c6298eeb
trac 8284 -- IntervalGraph generator and a bug in is_chordal

diff -r 556bb66e4c6d -r 1f6e22e68ddb sage/graphs/generic_graph.py
 a sage: g.is_chordal() True The disjoint union of chordal graphs is still chordal:: sage: (2*g).is_chordal() True Of course, the Petersen Graph is not chordal as it has girth 5 :: sage: g = graphs.PetersenGraph() Pacific J. Math 1965 Vol. 15, number 3, pages 835--855 """ if not self.is_connected(): for gg in self.connected_components_subgraphs(): if not gg.is_chordal(): return False return True peo,t_peo = self.lex_BFS(tree=True) if w not in seen: queue.append((w, d+1)) def lex_BFS(self,reverse=False,tree=False): def lex_BFS(self,reverse=False,tree=False, initial_vertex = None): r""" Performs a Lex BFS on the graph. INPUT: - reverse ( boolean ) -- whether to return the vertices - reverse (boolean) -- whether to return the vertices in discovery order, or the reverse. False by default. - tree (boolean) -- whether to return the discovery directed tree (each vertex being linked to the one that saw it for the first time) False by default. - initial_vertex -- the first vertex to consider. None by default. ALGORITHM: sage: g = graphs.PathGraph(3).lexicographic_product(graphs.CompleteGraph(2)) sage: g.lex_BFS(reverse=True) [(2, 1), (2, 0), (1, 1), (1, 0), (0, 1), (0, 0)] And the vertices at the end of the tree of discovery are, for chordal graphs, simplicial vertices (their neighborhood is a complete graph):: sage: g = graphs.ClawGraph().lexicographic_product(graphs.CompleteGraph(2)) sage: v = g.lex_BFS()[-1] sage: peo, tree = g.lex_BFS(initial_vertex = v,  tree=True) sage: leaves = [v for v in tree if tree.in_degree(v) ==0] sage: all([g.subgraph(g.neighbors(v)).is_clique() for v in leaves]) True """ id_inv = dict([(i,v) for (v,i) in zip(self.vertices(),range(self.order()))]) code = [[] for i in range(self.order())] pred = [-1]*self.order() add_element = (lambda y:value.append(id_inv[y])) if not reverse else (lambda y: value.insert(0,id_inv[y])) # Should we take care of the first vertex we pick ? first = True if initial_vertex is not None else False while vertices: v = max(vertices,key=l) if not first: v = max(vertices,key=l) else: v = self.vertices().index(initial_vertex) first = False vertices.remove(v) vector = m.column(v) for i in vertices:
• ## sage/graphs/graph_generators.py

diff -r 556bb66e4c6d -r 1f6e22e68ddb sage/graphs/graph_generators.py
 a from sage.misc.prandom import random intervals = [tuple(sorted((random(), random()))) for i in range(n)] intervals.sort() return self.IntervalGraph(intervals) def IntervalGraph(self,intervals): r""" Returns the graph corresponding to the given intervals. An interval graph is built from a list (a_i,b_i)_{1\leq i \leq n} of intervals : to each interval of the list is associated one vertex, two vertices being adjacent if the two corresponding (closed) intervals intersect. INPUT: - intervals -- the list of pairs (a_i,b_i) defining the graph. NOTE: The intervals (a_i,b_i) must verify `a_i