[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-24 Thread Aleksandr Mikheev
It works! Thank you.


[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Seth
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.
>


[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Seth
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.
>>
>

[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Aleksandr Mikheev
Really sorry for silly questions, but I am really new to Julia language and 
also I am not very good in coding generally.


[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Aleksandr Mikheev
Excuse me once again. How can I use rem_vertex!() now? I tried to update my 
package - didn't help. I tried to do a new file (called GraphFeatures), in 
witch I copied all the functions from here 

 - 
but it does not understand standart Graph type from LightGraphs:

ERROR: MethodError: `rem_vertex!` has no method matching 
> rem_vertex!(::LighGraphs.Graph, ::Int64)
> Closest candidates are:
>   rem_vertex!(::Union{GraphFeatures.DiGraph,GraphFeatures.Graph}, ::Int64)


 What should I do? 


[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Seth


On Monday, November 23, 2015 at 2:09:13 PM UTC-8, Aleksandr Mikheev wrote:
>
> Excuse me once again. How can I use rem_vertex!() now? I tried to update 
> my package - didn't help. I tried to do a new file (called GraphFeatures), 
> in witch I copied all the functions from here 
> 
>  - 
> but it does not understand standart Graph type from LightGraphs:
>
> ERROR: MethodError: `rem_vertex!` has no method matching 
>> rem_vertex!(::LighGraphs.Graph, ::Int64)
>> Closest candidates are:
>>   rem_vertex!(::Union{GraphFeatures.DiGraph,GraphFeatures.Graph}, ::Int64)
>
>
>  What should I do? 
>

Try this:

Pkg.clone("LightGraphs") # this makes sure you're on the most current code 
in master
Then exit / restart Julia REPL, and type "using LightGraphs" - this will 
force a recompile
rem_vertex!() should now be available for Graph and DiGraph:

julia> g = PathGraph(10)
{10, 9} undirected graph

julia> rem_vertex!(g,4)
{9, 7} undirected graph

If you have any other questions, please feel free to ask here or open up an 
issue on the LightGraphs repo.

Really sorry for silly questions, but I am really new to Julia language and 
> also I am not very good in coding generally.
>
 
Absolutely no need to apologize. Feel free to ask away.



[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Seth
Er. Sorry for the bad instructions. Don't use Pkg.clone("LightGraphs"), use 
Pkg.checkout("LightGraphs").

On Monday, November 23, 2015 at 2:31:42 PM UTC-8, Seth wrote:
>
>
>
> On Monday, November 23, 2015 at 2:09:13 PM UTC-8, Aleksandr Mikheev wrote:
>>
>> Excuse me once again. How can I use rem_vertex!() now? I tried to update 
>> my package - didn't help. I tried to do a new file (called GraphFeatures), 
>> in witch I copied all the functions from here 
>> 
>>  - 
>> but it does not understand standart Graph type from LightGraphs:
>>
>> ERROR: MethodError: `rem_vertex!` has no method matching 
>>> rem_vertex!(::LighGraphs.Graph, ::Int64)
>>> Closest candidates are:
>>>   rem_vertex!(::Union{GraphFeatures.DiGraph,GraphFeatures.Graph}, 
>>> ::Int64)
>>
>>
>>  What should I do? 
>>
>
> Try this:
>
> Pkg.clone("LightGraphs") # this makes sure you're on the most current code 
> in master
> Then exit / restart Julia REPL, and type "using LightGraphs" - this will 
> force a recompile
> rem_vertex!() should now be available for Graph and DiGraph:
>
> julia> g = PathGraph(10)
> {10, 9} undirected graph
>
> julia> rem_vertex!(g,4)
> {9, 7} undirected graph
>
> If you have any other questions, please feel free to ask here or open up 
> an issue on the LightGraphs repo.
>
> Really sorry for silly questions, but I am really new to Julia language 
>> and also I am not very good in coding generally.
>>
>  
> Absolutely no need to apologize. Feel free to ask away.
>
>

[julia-users] Re: What is the best way to delete unwanted subgraph?

2015-11-23 Thread Seth
...and just to follow up, rem_vertex!() is now in LightGraphs master. This 
will be more efficient if the connected components you're trying to remove 
are small relative to the ones you want to preserve.


On Monday, November 23, 2015 at 5:28:04 AM UTC-8, Seth wrote:
>
> 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.
>>>
>>