Conversation
with test updated export and runtests.jl
add the test for subgraphs.jl
This is great - thanks very much. Could we put this in operators.jl, though, and just call the functions "subgraph"? |
Yes it can go in operators. From wolfram mathworld: A vertex-induced subgraph (sometimes simply called an "induced subgraph") is a subset of the vertices of a graph G together with any edges whose endpoints are both in this subset. In the future we can support "graph minor" where the vertices are collapsed into each other by "edge contraction" http://mathworld.wolfram.com/GraphMinor.html although I don't have time to implement graph minor like i just did with induced subgraph. |
OK - move to operators, keep the name :) But let's figure out why Travis is failing first. |
ah, the docstring. Perhaps just leave it as a comment for now? |
I used @doc so it didn't work on 0.3. I only use 0.4 locally. Either a version check or |
ok that's fine too but then we need to add it to doc/somewhere to get it in read the docs |
I'll put it in RTD in a new commit. No worries. |
i think i beat you to it? |
Hah. ok. One other thing - does it make sense to test iter against g? that is, error if any element of iter > nv(g)? |
you won't get an error if you don't. when iterating over the edges you will never try that vertex. I'm inclined to follow the philosophy of handling argument diversity in the caller. We don't know how the iterable will be generated. |
Yup, I see it (and agree with your philosophy). Will merge once travis comes back green - thanks :) |
(disclaimer: agree with your philosophy except for add_edge!, where I error if the edge already exists.) |
BTW: thanks for this. I can't wait to try it out! |
Oh - one other thing (post merge): is this intended to work for directed graphs as well? If so, it needs a change:
If not, it needs to a change to only accept Graph (instead of AbstractGraph). |
fixed it pretty cool that typeof(g)(n) works to construct the same type of
g. I just guessed that it would work and it did.
|
Better way to do that is as follows:
Let me code something up. I also think we can get more efficiency by using finclist of the original graph. I'll do some testing. |
easy to use function
function inducedsubgraph(g::AbstractGraph, iter)
which returns the new graph and the vertex name map as a Dict.worker function for filtering that does not allocate any temporaries.
@doc "inplace filtering for preallocated output, edge iterable, vertex mapping" -> function inducedsubgraph!(h::AbstractGraph, edges, newvid)