JuliaGraphs / GraphsBase.jl

Basic interface and structures for the JuliaGraphs ecosystem
http://juliagraphs.org/GraphsBase.jl/
MIT License
11 stars 1 forks source link

Provide optional weights and metadata in one graph type #27

Open CameronBieganek opened 8 months ago

CameronBieganek commented 8 months ago

I think it's worth considering having one Graph type that can optionally include weights and metadata for an undirected graph, rather than having separate WeightedGraph and MetaGraph types. The Graph constructor could have various optional type parameters, so you could create empty graphs like this:

# Create a graph with `Any` vertex type, Float64 edge weights,
# and no metadata.
Graph()

# Char graph with Float64 edge weights:
Graph{Char}()

# Char graph with Int weights:
Graph{Char, Int}()  

# Char graph with Float64 edge weights and
# vertex data of type MyVertexData:
Graph{Char, Float64, MyVertexData}()

# Char graph with Float64 edge weights,
# vertex data of type MyVertexData,
# and edge data of type MyEdgeData:
Graph{Char, Float64, MyVertexData, MyEdgeData}()

# Char graph with Float64 edge weights,
# no vertex data, and edge data of type MyEdgeData:
Graph{Char, Float64, Nothing, MyEdgeData}()

Nothing would be an option for the metadata type parameters, but not for the vertex type and weight type. (Default weight type would probably be Float64.)

gdalle commented 8 months ago

I like the idea, and from a user perspective it would be closer to the nice NetworkX experience. The only doubt I have is the overhead incurred by carrying empty vertex or edge metadata, but it's probably minor