JuliaGraphs / JuliaGraphs/Graphs.jl
`todirected` and `toundirected` interfaces
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 538
- Forks
- 128
- Avg merge
- 10h 25m
- Merged PRs (30d)
- 2
Description
Hi. I think it would be nice to define here these two interface functions.
Some pseudocode:
"""
todirected(g::AbstractGraph)
Create a directed instance of graph `g`.
If `g` is already directed, return `g` unchanged.
"""
@tratfn todirected(g::AbstractGraph::IsDirected) = g
@tratfn todirected(g::AbstractGraph::!(IsDirected)) = error("not implemented")
"""
toundirected(g::AbstractGraph)
Create a undirected instance of graph `g`.
If `g` is already undirected, return `g` unchanged.
"""
@traitfn toundirected(g::AbstractGraph::::!(IsDirected)) = g
@traitfn toundirected(g::AbstractGraph::::IsDirected) = error("not implemented")
The implementation for Simple(Di)Graph is quite easy:
toundirected(g::SimpleDiGraph) = SimpleGraph(g)
todirected(g::SimpleGraph) = SimpleDiGraph(g)
This will help across all the Graphs julia community with packages wanting to define other graphs (e.g. MetaGraph, Multigraph).
I think it's a nice interface to have.
Let me know if you are interested and I could try to find some time to make a PR :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing AbstractGraph interface and the SimpleGraph and SimpleDiGraph conversion methods. Confirm the directed and undirected behavior described in the issue, then add coverage for conversions in both directions and unchanged results for graphs already in the requested form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100