Keep in mind that induced subgraphs will not preserve vertex numbering, so 
if you do something like

G = G[4,5,6]

your old vertices 4, 5, and 6 will be renumbered so that the new G has 
vertices in the range 1 : 3.



On Monday, November 23, 2015 at 5:23:55 AM UTC-8, Seth wrote:
>
> Aleksandr,
>
> The easiest way to do this is something like the following:
>
> cc = connected_components(G)
> G = G[cc[1]]
>
>
> This replaces G with the induced subgraph made up of the vertices in the 
> first connected component. (You can create a new graph H if you want to 
> keep G.)
>
> We are also implementing rem_vertex!() soon thanks to Carlo Lucibello, but 
> it's not in master yet and it's probably not as performant as the above.
>
> Thanks,
>
> Seth.
>
>
> On Monday, November 23, 2015 at 5:17:33 AM UTC-8, Aleksandr Mikheev wrote:
>>
>> Hi all,
>>
>> I'm currently using LightGraphs package in my student research work. And 
>> I have some problems with it. Imagine we have a undirrected graph G, which 
>> contains, for example, 10 vertices and some edges. I would like to know 
>> which components of graph G are connected, so I call 
>> "connected_components(G)". Suppose I have this situation:
>>
>> julia> connected_components(G)
>> 6-element Array{Array{Int64,1},1}:
>> [1,2,3]
>> [4,7]
>> [5]
>> [6]
>> [8,9]
>> [10]
>>
>> And now I would like to delete all subgraphs, except [1,2,3]. In other 
>> words, I would like to have subgraph [1,2,3] as a graph G further. Is there 
>> any effective methods to do this in LightGraphs or in any other packages? I 
>> mean, I can delete vertices one by one (I guess I saw this function 
>> somewhere in GitHub), but that would be pretty slow, I imagine.
>>
>> Thank you in advance.
>>
>

Reply via email to