Skip to content
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

todirected and toundirected interfaces #220

Open
filchristou opened this issue Feb 2, 2023 · 1 comment
Open

todirected and toundirected interfaces #220

filchristou opened this issue Feb 2, 2023 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@filchristou
Copy link
Contributor

filchristou commented Feb 2, 2023

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 :)

@gdalle
Copy link
Member

gdalle commented Jun 16, 2023

I think this would help a lot!
Related: #98

@gdalle gdalle added the enhancement New feature or request label Jun 16, 2023
@gdalle gdalle added this to the v2.0 milestone Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants