-
Notifications
You must be signed in to change notification settings - Fork 81
Enable graphs with different Vertex and Edge types #126
Comments
Why can't you just do function add_vertex!{V1, V2}(g::GenericGraph{V1}, v::V2) and ensure that V1 and V2 are valid types defined somewhere in the module? |
I could do that. It is is a looser type constraint (V2 could be anything) but the main problem is that I'll still be duplicating all the code that exists in Graphs.jl already. |
Hmm, this question might be better answered on the julia-users mailing list. https://groups.google.com/forum/#!forum/julia-users I would try that forum. |
I encounter a similar problem. I tried to create vertex and edges types because I wanted to create some fixed variables to the vertices and edges: type VertexGraph
id::UInt32
S::Array{Float64,1}
V::Float64
function VertexGraph(id::Integer)
new(id, Float64[0], 0)
end
end
type EdgeGraph{V}
id::UInt32
source::V
target::V
Q::Float64
action::Array{Float64, 1}
ap::Array{Float64, 1}
function EdgeGraph(id::Integer, source::V, target::V)
new(id, source, target, 0, [0], [0])
end
end The problem is that since there's not such thing as
In the meantime I'm using |
In working on a constraint solving package, I wanted to use Graphs.jl to create graphs with different types of Vertices. I attempted to do this using an abstract Vertex type, and vertices are subtypes of that abstract type.
I found myself having to reimplement several methods such as
add_vertex!
add_edge!
with the same body, but slightly different type signature, because they were not designed for this use case. For illustration considerReally, I believe I want something like
But this is not valid Julia, so I am not sure how one would achieve this. Or perhaps there is a simple work around?
The text was updated successfully, but these errors were encountered: