Repository navigation
feat: add directed star graph - #8151
Conversation
rossbar
left a comment
There was a problem hiding this comment.
The important question here is one of semantics. To my mind, there are three possible interpretations of a directed star graph:
- Directed edges originating from the "root" (what's proposed in this PR)
- Directed edges originating from the "leaves" pointed towards the root
- Bidirectional edges
Without any concrete background in graph theory, I have no idea if any of these is the "accepted" definition. Note that NetworkX does different things for different graphs with create_using=DiGraph. For example, path_graph creates directional paths from "start" to "finish" while complete_graph creates bidirectional edges.
So the question is, do we want to make star_graph(n, create_using=nx.DiGraph) mean option 1. If the graph theory literature agrees on this definition, I'm +0.5 - else I'm -1. I'd generally tend towards explicitness: it's pretty straightforward (and only a couple characters longer) to replace nx.star_graph(n, create_using=nx.DiGraph) with nx.DiGraph([(0, n) for n in range(1, n + 1)]).
|
I think this is actually option 3 from your list, because that's the one that made sense in my use case, and because it's the one that's "hardest" to write.
|
|
I'd definitely not want to pollute the API with functions for each option. I'd be much more inclined to add docstring examples. |
|
I believe the bidirectional case is This type of thing is a motivating example for the NXEP we explored a while back involving making versions of the generators that return the edges and nodes rather than the full graph. But docstring examples might do the trick here. I don't think there is much difference in performance either but I haven't checked. |
|
Okay, how about this:
|
dschult
left a comment
There was a problem hiding this comment.
This looks like a reasonable approach. +1 for the discussion and examples in the doc_string. And this adds functionality (can be directed which used to raise) so I believe no deprecation is needed.
I approve this PR
rossbar
left a comment
There was a problem hiding this comment.
Sounds good to me - I trust everyone's opinion about what makes the most sense from a definition standpoint and have no strong sense of my own! Implementation-wise everything looks good!
While working on #8148, directed star graphs would have been useful to easily created directed graphs with many "leaf nodes" in their DFS tree. This PR implements adds that possibility and adds a test for it.