summaryrefslogtreecommitdiff
path: root/networkx/algorithms/distance_regular.py
diff options
context:
space:
mode:
authorJeffrey Finkelstein <jeffrey.finkelstein@gmail.com>2015-06-17 00:52:55 -0400
committerJeffrey Finkelstein <jeffrey.finkelstein@gmail.com>2015-07-30 17:42:45 -0400
commiteb2f2d8ebb9dd5df2d80d385746666a975417e77 (patch)
treeb0ed35686539f30dbf2ee874f43d35291325cd04 /networkx/algorithms/distance_regular.py
parent3b1cc3011066fa041fdac18b4a1e9caec82f4c4e (diff)
downloadnetworkx-eb2f2d8ebb9dd5df2d80d385746666a975417e77.tar.gz
PEP8 fixes to distance_regular.
Diffstat (limited to 'networkx/algorithms/distance_regular.py')
-rw-r--r--networkx/algorithms/distance_regular.py59
1 files changed, 29 insertions, 30 deletions
diff --git a/networkx/algorithms/distance_regular.py b/networkx/algorithms/distance_regular.py
index c17744d7..e057228e 100644
--- a/networkx/algorithms/distance_regular.py
+++ b/networkx/algorithms/distance_regular.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011 by
+# Copyright (C) 2011 by
# Dheeraj M R <dheerajrav@gmail.com>
# Aric Hagberg <aric.hagberg@gmail.com>
# All rights reserved.
@@ -8,15 +8,14 @@
Distance-regular graphs
=======================
"""
-from itertools import product
-
import networkx as nx
from networkx.utils import not_implemented_for
__author__ = """\n""".join(['Dheeraj M R <dheerajrav@gmail.com>',
'Aric Hagberg <aric.hagberg@gmail.com>'])
-__all__ = ['is_distance_regular','intersection_array','global_parameters']
+__all__ = ['is_distance_regular', 'intersection_array', 'global_parameters']
+
def is_distance_regular(G):
"""Returns True if the graph is distance regular, False otherwise.
@@ -41,7 +40,7 @@ def is_distance_regular(G):
>>> G=nx.hypercube_graph(6)
>>> nx.is_distance_regular(G)
True
-
+
See Also
--------
intersection_array, global_parameters
@@ -52,18 +51,19 @@ def is_distance_regular(G):
References
----------
- .. [1] Brouwer, A. E.; Cohen, A. M.; and Neumaier, A.
+ .. [1] Brouwer, A. E.; Cohen, A. M.; and Neumaier, A.
Distance-Regular Graphs. New York: Springer-Verlag, 1989.
- .. [2] Weisstein, Eric W. "Distance-Regular Graph."
+ .. [2] Weisstein, Eric W. "Distance-Regular Graph."
http://mathworld.wolfram.com/Distance-RegularGraph.html
"""
try:
- a=intersection_array(G)
+ intersection_array(G)
return True
except nx.NetworkXError:
return False
+
def global_parameters(b, c):
"""Return global parameters for a given intersection array.
@@ -71,7 +71,7 @@ def global_parameters(b, c):
such that for any 2 vertices x,y in G at a distance i=d(x,y), there
are exactly c_i neighbors of y at a distance of i-1 from x and b_i
neighbors of y at a distance of i+1 from x.
-
+
Thus, a distance regular graph has the global parameters,
[[c_0,a_0,b_0],[c_1,a_1,b_1],......,[c_d,a_d,b_d]] for the
intersection array [b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d]
@@ -97,13 +97,13 @@ def global_parameters(b, c):
References
----------
- .. [1] Weisstein, Eric W. "Global Parameters."
- From MathWorld--A Wolfram Web Resource.
- http://mathworld.wolfram.com/GlobalParameters.html
+ .. [1] Weisstein, Eric W. "Global Parameters."
+ From MathWorld--A Wolfram Web Resource.
+ http://mathworld.wolfram.com/GlobalParameters.html
See Also
--------
- intersection_array
+ intersection_array
"""
return ((y, b[0] - x - y, x) for x, y in zip(b + [0], [0] + c))
@@ -117,7 +117,7 @@ def intersection_array(G):
are exactly c_i neighbors of y at a distance of i-1 from x and b_i
neighbors of y at a distance of i+1 from x.
- A distance regular graph'sintersection array is given by,
+ A distance regular graph's intersection array is given by,
[b_0,b_1,.....b_{d-1};c_1,c_2,.....c_d]
Parameters
@@ -126,7 +126,7 @@ def intersection_array(G):
Returns
-------
- b,c: tuple of lists
+ b,c: tuple of lists
Examples
--------
@@ -136,10 +136,9 @@ def intersection_array(G):
References
----------
- .. [1] Weisstein, Eric W. "Intersection Array."
- From MathWorld--A Wolfram Web Resource.
+ .. [1] Weisstein, Eric W. "Intersection Array."
+ From MathWorld--A Wolfram Web Resource.
http://mathworld.wolfram.com/IntersectionArray.html
-
See Also
--------
@@ -147,15 +146,15 @@ def intersection_array(G):
"""
# test for regular graph (all degrees must be equal)
degree = G.degree_iter()
- (_,k) = next(degree)
- for _,knext in degree:
+ (_, k) = next(degree)
+ for _, knext in degree:
if knext != k:
raise nx.NetworkXError('Graph is not distance regular.')
k = knext
- path_length = nx.all_pairs_shortest_path_length(G)
+ path_length = nx.all_pairs_shortest_path_length(G)
diameter = max([max(path_length[n].values()) for n in path_length])
- bint = {} # 'b' intersection array
- cint = {} # 'c' intersection array
+ bint = {} # 'b' intersection array
+ cint = {} # 'c' intersection array
for u in G:
for v in G:
try:
@@ -163,13 +162,13 @@ def intersection_array(G):
except KeyError: # graph must be connected
raise nx.NetworkXError('Graph is not distance regular.')
# number of neighbors of v at a distance of i-1 from u
- c = len([n for n in G[v] if path_length[n][u]==i-1])
+ c = len([n for n in G[v] if path_length[n][u] == i - 1])
# number of neighbors of v at a distance of i+1 from u
- b = len([n for n in G[v] if path_length[n][u]==i+1])
+ b = len([n for n in G[v] if path_length[n][u] == i + 1])
# b,c are independent of u and v
- if cint.get(i,c) != c or bint.get(i,b) != b:
+ if cint.get(i, c) != c or bint.get(i, b) != b:
raise nx.NetworkXError('Graph is not distance regular')
- bint[i] = b
- cint[i] = c
- return ([bint.get(i,0) for i in range(diameter)],
- [cint.get(i+1,0) for i in range(diameter)])
+ bint[i] = b
+ cint[i] = c
+ return ([bint.get(j, 0) for j in range(diameter)],
+ [cint.get(j + 1, 0) for j in range(diameter)])