JuliaGraphs / JuliaGraphs/Graphs.jl

`todirected` and `toundirected` interfaces

Open
#220 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.