Repository navigation
Add: Shrikhande graph - #8884
Conversation
rossbar
left a comment
There was a problem hiding this comment.
The proposal seems reasonable to me - the Wikipedia article is interesting and the named graph seems to be well-established and discoverable.
Some high-level questions:
- Why the tuple nodes - are the tuples significant in some way?
- Almost certainly related: is there a procedure for generating this graph that doesn't involve hard-coded nodes? If so, the procedure itself could be more desirable than the hard-coded version. Similarly, if the procedure is a general one (i.e. capable of producing other graphs from a set of parameters) the question becomes whether it wouldn't be better to add that and include the construction of the Shrikhande graph as an example.
- Is there a natural concept of a "directed" Shrikhande graph? If users pass in
create_using=nx.DiGraphthey will indeed get a graph with directed edges from this formulation. Are the edge directions meaningful?
|
@rossbar Thank you for your thoughtful reply.
It follows the definition provided in the Wikipedia article:
Yes, I will rewrite as follows. @_raise_on_directed
@nx._dispatchable(graphs=None, returns_graph=True)
def shrikhande_graph(create_using=None):
r"""
Returns the Shrikhane Graph.
The Shrikhande graph has 16 nodes and 48 edges.
This graph can be constructed as a Cayley graph [1]_.
The vertex set is $\mathbb{Z}_4 \times \mathbb{Z}_4$.
Two vertices are adjacent if and only if the difference is in
$\{\pm(1, 0), \pm(0, 1), \pm(1, 1)\}$.
Parameters
----------
create_using : NetworkX graph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated.
Returns
-------
G : networkx Graph
Shrikhande Graph with 16 nodes and 48 edges
References
----------
.. [1] https://en.wikipedia.org/wiki/Shrikhande_graph
"""
from itertools import product
_ = [(1, 0), (0, 1), (1, 1), (-1, 0), (0, -1), (-1, -1)]
G = nx.Graph((((u, v), ((u+w) % 4, (v+x) % 4))
for (u, v), (w, x) in product(product(range(4), range(4)), _)),
create_using=create_using,)
G.name = "Shrikhande Graph"
return GSince general constructions follow the Cayley graph, this may present a challenge. This lies at the intersection of graph theory and algebra (group theory).
You are asking whether you should use The code in the PR is based on the Petersen graph code. On the other hand, the Frucht graph and the Paley graph does not have |
|
How about the following code (trying to be clear -- ignoring optimization cuz its so small.) def shrikhande_graph():
<docs>
# basic 2d 4x4 periodic grid but only connect to the East, North and NE.
# Missing edges are SE and NW. The others get filled in by wraparound.
# |/|/|/|/
# O-O-O-O-
# |/|/|/|/ Circle is a node.
# O-O-O-O- Wrap is shown
# |/|/|/|/ using lines heading
# O-O-O-O- to the right and up.
# |/|/|/|/
# O-O-O-O-
rows = cols = range(4)
plus_one = [1, 2, 3, 0]
G = nx.Graph()
G.add_edges_from(((x, y), (plus_one[x], y)) for x in rows for y in cols)
G.add_edges_from(((x, y), (x, plus_one[y])) for x in rows for y in cols)
G.add_edges_from(((x, y), (plus_one[x], plus_one[y])) for x in rows for y in cols)
return GGeneralizations could also be based off the 2d-grid approach I think directedness should be handled like Petersen graph. |
|
@dschult Thank you for your quick reply. Clearly, your code is better than mine. It is more readable, intuitive and insightful. Starting with a 4x4 grid shows that the Shrikhande graph is a toroidal (genus one) graph. This information is not included in the Wikipedia article on the Shrikhande graph. However, there is a short script in MathWorld which suggests that E. Weisstein has also recently noticed this. I added the MathWorld reference to
Yes, I do. |
Co-authored-by: Dan Schult <[email protected]>
dschult
left a comment
There was a problem hiding this comment.
I've gone through this one more time. I think we should add a down-to-earth description of the graph as a first paragraph -- then have the paragraph describing the properties of the graph (related to Cayley graphs, the formula for which nodes connectm etc).
Notes: we should
- change "vertex" to "node" in the description to match the networkx preferred term.
- add a link/hook in the docs so the function shows in the docs (in the "small" sectin of
doc/reference/generators.rst - maybe remove the words "with 16 nodes and 48 edges" from the "Returns" section of the doc-string.
I made a suggestion for the paragraph, but feel free to change that as you think appropriate.
Co-authored-by: Dan Schult <[email protected]>
|
Thank you @dschult for suggestions.
I checked and corrected. In the
I checked and added entry
I checked and remove "with 16 nodes and 48 edges", however, this sentence was written in reference to Frucht graph. If it would be better to make corrections for Frucht graph, I will do so. |
dschult
left a comment
There was a problem hiding this comment.
Haha -- yes, it looks like about half the graphs in small.py add the number of nodes and edges to the description of what is returned. And the other half don't have that info. Let's leave it as you've got it.
I'd rather leave the hoffman_singleton_graph and frucht_graph as they are -- We could easily get sucked into docs changes for consistency sake and this could become a large PR indeed. :)
I approve this PR :} Thanks @satemochi
Hi, NetworkX maintainers and NetworkX community,
I recommend adding the Shrikhande graph to the list of named graphs.
If this graph is not impactful or if the list is complete then please reject this PR immediately.
The Shrikhande graph is an important graph in spectral graph theory, similar to nx.paley_graph(13).They are both graceful graphs.
I wrote another snippet of code that can be found here. This code gives two major layouts with the minimum coloring for testing correctness as follows:
