Commit 67a38da0 authored by Radek Hušek's avatar Radek Hušek
Browse files

groupConnectivityNaive: small optimizations

parent 29532439
from sage.graphs.graph import Graph, DiGraph
def flowEnumerator(G, group):
"""Enumerate all flows of given graph.
......@@ -33,7 +35,7 @@ def flowEnumerator(G, group):
yield tuple(v)
def testGroupConnectivityNaive(G_, group, forb_spanning_tree = False,
def testGroupConnectivityNaive(G_, group, forb_spanning_tree = True,
list_all = False, counts = False):
E = [ (u, v, i) for i, (u, v, _) in enumerate(G_.edges()) ]
G = DiGraph([G_.vertices(), E], format='vertices_and_edges')
......@@ -61,7 +63,7 @@ def testGroupConnectivityNaive(G_, group, forb_spanning_tree = False,
mask[e] = None
def is_compatible(f, x):
for i in range(m):
for i in xrange(m):
if f[i] == x[i]:
return False
return True
......@@ -90,9 +92,8 @@ def testGroupConnectivityNaive(G_, group, forb_spanning_tree = False,
return False
else:
def find_flow(forb):
c = len(filter(lambda f: is_compatible(f, forb), flows))
C[forb] = c
return (c > 0)
C[forb] = filter(lambda f: is_compatible(f, forb), flows)
return (len(C[forb]) > 0)
ret = []
......@@ -100,7 +101,7 @@ def testGroupConnectivityNaive(G_, group, forb_spanning_tree = False,
if not find_flow(forb):
if not list_all:
return (False, info, [forb])
ret.append(list(forb))
ret.append(forb)
return (len(ret) == 0, info, ret)
......@@ -108,4 +109,14 @@ def labelsFromArray(G, E, labels):
for (u, v, i) in E:
G.set_edge_label(u, v, labels[i])
def dictMap(f, d):
return { k: f(v) for k, v in d.iteritems() }
def myHistogram(data):
s = dict()
for i in data:
if i not in s:
s[i] = 0
s[i] += 1
return s
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment