-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implemented power of graph function under basic methods #36584
Conversation
It would be better to implement method For instance, other = self.copy()
for u in self:
for v in self.breadth_first_search(u, distance=k):
other.add_edge(u, v) One difficulty is to deal with (di)graphs with loops and/or multiple edges. |
For your information, we also have method |
Sir the code suggested by your works fine with digraphs with loops and multiple edges I will raise the PR with the changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The coding style must be improved (see how it is done in other methods) and some care is needed for graphs with multiple edges.
@dcoudert does the code seem fine? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Check and correct the doctest errors reported by the CI
- Although it is currently possible to import
DiGraph
fromsage.graphs.graph
, please don't do that. - Check and document the expected result when
k < 0
,k = 0
,k=1
,k=+oo
- Respect the 80 columns mode in comments and doctests, as done in other methods.
- Add empty line after
INPUT:
andOUTPUT:
as done in other methods. - Set the name of the graph before returning it.
- Add a
TESTS::
block and check the behavior of the method in corner cases, when the graph has multiple edges
@dcoudert What do you mean by |
sage: G = graphs.PetersenGraph()
sage: G
Petersen graph: Graph on 10 vertices
sage: G.name("a cool name") # Here we change the name
sage: G
a cool name: Graph on 10 vertices
sage: G = Graph(name="My empty graph") # Here we set the name of a new graph
sage: G
My empty graph: Graph on 0 vertices |
For eg.: in the following test
|
No, there is no need to name the graph here. I'm saying that you can set the name inside the method, as is done for instance in method sage: G = graphs.PetersenGraph()
sage: H = G.complement()
sage: H
complement(Petersen graph): Graph on 10 vertices
sage: H.name()
'complement(Petersen graph)' |
Documentation preview for this PR (built with commit e0dc49d; changes) is ready! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
…hods ### Description This PR introduces a new function, `power_of_graph`, to compute the kth power of an undirected, unweighted graph efficiently using the shortest distances method. The proposed function leverages Breadth-First Search (BFS) to calculate the power graph, providing a practical and scalable solution. ### Why is this change required? The change is required to address the need for efficiently calculating the kth power of a graph, a fundamental operation in graph theory. The PR aims to incorporate this feature into the SageMath library. Fixes sagemath#36582 ### Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion (if applicable). - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies sagemath#36582 : To implement power of graph URL: sagemath#36584 Reported by: saatvikraoIITGN Reviewer(s): David Coudert, saatvikraoIITGN
Description
This PR introduces a new function,
power_of_graph
, to compute the kth power of an undirected, unweighted graph efficiently using the shortest distances method. The proposed function leverages Breadth-First Search (BFS) to calculate the power graph, providing a practical and scalable solution.Why is this change required?
The change is required to address the need for efficiently calculating the kth power of a graph, a fundamental operation in graph theory. The PR aims to incorporate this feature into the SageMath library.
Fixes #36582
Checklist
⌛ Dependencies
#36582 : To implement power of graph