#13503: Enhancement of `is_triangle_free' addition of `triangles_count' and a
minor
change in `spanning_trees_count'
----------------------------------------------------------+-----------------
Reporter: azi | Owner:
jason, ncohen, rlm
Type: enhancement | Status:
needs_work
Priority: minor | Milestone:
sage-5.4
Component: graph theory | Resolution:
Keywords: triangles, graphs, number of triangles | Work issues:
Report Upstream: N/A | Reviewers:
David Coudert
Authors: Jernej Azarija | Merged in:
Dependencies: | Stopgaps:
----------------------------------------------------------+-----------------
Comment (by dcoudert):
Right.
A reasonably fast alternative to matrix multiplication (could be
improved):
{{{
def my_is_triangle_free_bitset(G):
map = {}
i = 0
for u in G.vertex_iterator():
map[u] = i
i += 1
B = {}
for u in G.vertex_iterator():
B[u] = Bitset([map[i] for i in G.neighbor_iterator(u)])
BB = {}
for u in G.vertex_iterator():
BB[u] = Bitset()
for v in G.vertex_iterator():
if B[u]&B[v]:
BB[u].add(map[v])
return not any(B[u]&BB[u] for u in G.vertex_iterator())
def toto(G):
M = G.am()
return not (M*M*M).trace()
}}}
{{{
sage: G = graphs.CompleteBipartiteGraph(3,3)
sage: %timeit toto(G)
625 loops, best of 3: 256 µs per loop
sage: %timeit my_is_triangle_free_bitset(G)
625 loops, best of 3: 132 µs per loop
sage:
sage: G = graphs.CompleteBipartiteGraph(30,30)
sage: %timeit toto(G)
25 loops, best of 3: 15 ms per loop
sage: %timeit my_is_triangle_free_bitset(G)
125 loops, best of 3: 6.99 ms per loop
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13503#comment:21>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.