JuliaGraphs / Networks.jl

(DEPRECATED) Additional graph flexibility for LightGraphs
Other
3 stars 4 forks source link

Create function definitions that make Networks operate as LightGraphs.Graph transparently #4

Open jpfairbanks opened 8 years ago

jpfairbanks commented 8 years ago

In #1 we discussed the need for the Network type to behave as a Graph when calling LightGraphs functions. In this way we are extending the behavior of the type Graph by embedding it into another type. One way to do this is with some metaprogramming that takes every function in a list and creates a new function that first converts the first argument to a SimpleGraph.

The goal is to generate for each function in some list f(g::SimpleGraph, args...)->f(convert(SimpleGraph, network), args...)

CarloLucibello commented 8 years ago

I did some investigations, it looks like we can go through the methods of LightGraphs using something like

fun = filter(x->    x!=:CombinatorialAdjacency
                    && string(x)[end]!= '!'
                    && (string(x)[1] == 'Δ' || !isupper(string(x)[1]))
                    && isa(eval(x),Function)
        , names(LightGraphs))

m=methods(fun[1])
defs = m.defs
defs = defs.next

Though I fear that without a layer of abstraction in LightGraphs (JuliaGraphs/LightGraphs.jl#227 again), so that we could use inheritance instead of composition, this will look like an ugly and unstable hack

jpfairbanks commented 8 years ago

The Go programming language does not have any inheritance and uses composition for everything. After working in Go for a while, I find composition better than inheritance. I think that using macros we can support it now and the language support will get better in the future. Between the two of us, we have spent more time thinking about how to do it with metaprogramming than it would have taken to just change the code. :smiley:

promotion.jl just contains a table of functions that should convert their arguments to a common number type before application. We could use a similar table to avoid metaprogramming. https://github.com/JuliaLang/julia/blob/master/base/promotion.jl#L172

You could even write the table with sed.

CarloLucibello commented 8 years ago

but promote operates alway between two objects, how would you use it to automatically cast a single object from one type to another?

PS see also https://groups.google.com/forum/#!topic/julia-users/No5oe0RB5lI