subgraph of an acyclic graph covering some selected nodes but other nodes not on the path
By : JakenVeina
Date : March 29 2020, 07:55 AM
wish helps you I feel like I misunderstood the problem but let's give it a try. First we have to assume/check that your graph is a connected component http://en.wikipedia.org/wiki/Connected_component_(graph_theory) and then you can start : code :
solution = sV
foreach n1 in sv
foreach n2 in sv, n2!=n1
path = findPath(G,n1,n2)
// this should return at least one path because of connectivity
// and no more than one
for each n3 in path
solution += n3

R and igraph: subgraph nodes based on attributes of other nodes that are incident on edge
By : Avdesh
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have collaboration data of inventors on patents. Each inventor is a node, each edge represents a patent on which two inventors have collaborated. Some patents have >2 inventors, so some patents are represented with multiple edges. , How about this code :
#final all patent names
patents < unique(edge.attributes(gg)$patent)
#check if criteria are met for patent
okpatents < sapply(patents, function(p){
cities < V(gg)[inc(E(gg)[patent==p])]$city
nc < sum(cities=="BOISE")
return(nc>0 & nc < length(cities))
})
#extract subgraph
gs < subgraph.edges(gg, E(gg)[patent %in% patents[okpatents]])
#verify
plot(gs, edge.label=E(gs)$patent)

Getting subgraph of nodes between two nodes?
By : Coolroe
Date : March 29 2020, 07:55 AM
like below fixes the issue My answer is very similar to back2basics, but more directly finds the nodes between the two. If there is a path from source to target, that path will be found by nx.all_simple_paths(G, source=source, target=target) which returns a generator for the paths. code :
import networkx as nx
G = nx.Graph()
G.add_edges_from([(1, 2), (2, 3), (3, 4), (3, 5), (4, 6), (5, 6), (3, 7), (7, 6), (6, 8), (8, 9)])
paths_between_generator = nx.all_simple_paths(G,source=3,target=6)
nodes_between_set = {node for path in paths_between_generator for node in path}
SG = G.subgraph(nodes_between_set)
nodes_between_set = set()
for path in paths_beween_generator:
for node in path:
nodes_between_set.add(node)

r igraph  Identify ties of nodes to a subgraph regardless of affiliation to said subgraph
By : Isatron3000
Date : October 14 2020, 09:38 AM
Any of those help How to count the ties of a node to a subgraph of the same graph? In a school context, how to count student G's friends in a specific class, regardless of her belonging there? , You can get the neighbours first, and use them to subset schoolsub: code :
nbs < neighbors(schoolgraph, "G")$name
V(schoolsub)$name[V(schoolsub)$name %in% nbs]
#[1] "A" "C"

Nodes or set of nodes connected to a subgraph networkx
By : Adam Darwin
Date : March 29 2020, 07:55 AM
this one helps. If B is strongly connected, then if you choose any node u in B, then if some node x in A has a path to some node b in B, then there is a path from x to u (there is a path from b to u because B is strongly connected and then the x to b to u path exists). So having a path to any node in B is the same thing as having a path to one specific node in B. Let X be the set of nodes with a path to u. This is the set you want. If you do X = nx.ancestors(A, u) then X is the set of nodes with a path to u. If you want the subgraph itself, then do G = A.subgraph(X), but if you just want the set of nodes, then it's X.

