graph_intersection#
- graph_tool.generation.graph_intersection(g1, g2, eweight1=None, eweight2=None, vmap='identity', props=[], mt='set', internal_props=False, in_place=False, **kwargs)[source]#
Return a graph containing the intersection of the edges of graphs
g1
andg2
.- Parameters:
- g1
Graph
Graph to be subtracted from.
- g2
Graph
Graph to be compared to.
- eweight1
EdgePropertyMap
(optional, default:None
) If provided, this will determine the weights of the edges of graph
g1
. If not provided, each edge will be assumed to have unity weight.- eweight2
EdgePropertyMap
(optional, default:None
) If provided, this will determine the weights of the edges of graph
g2
. If not provided, each edge will be assumed to have unity weight.- vmap
VertexPropertyMap
,"identity"
, orNone
(optional, default:None
) Vertex property map owned by
g2
which maps each of its vertices to vertex indices belonging tog1
, in which case they are considered to be identical. Negative values mean no mapping exists, and thus both vertices ing1
andg2
will be present in the intersection graph. If this argument is not provided (i.e.vmap
isNone
), both vertex sets will be added to the intersection. Ifvmap
isg2.vertex_index
, and the vertex indexes are identical in both graphs, the intersection will correspond only to the edge sets. A special value ofvmap == "identity"
is a shortcut forvmap = g2.vertex_index
.- propslist of tuples of
PropertyMap
(optional, default:[]
) Property maps to be included in the intersection. Each element of th list must be a pair of
PropertyMap
objects. The first element must be a property ofg1
, and the second ofg2
. If either value isNone
, an new map will be created, and set to appropriately empty values.- mt
str
(otional, default:"set"
) Merge rule for property values. Should be one of
"set"
,"sum"
,"diff"
,"idx_inc"
,"append"
,"concat"
. Seegraph_merge()
for further documentation.- internal_props
bool
(optional, default:False
) If
True
all internal property maps ofg1
andg2
will be included in the intersection.- in_place
bool
(optional, default:False
) If
True
, the intersection is obtained in-place by subtracting edges fromg1
, which is then modified. IfFalse
, a new graph is created, and both graphs remain unmodified.- **kwargs
dict
(optional, default:{}
) Remaining keyword parameters will be forwarded to
graph_merge()
.
- g1
- Returns:
- ug
Graph
The intersection graph.
- w
EdgePropertyMap
The edge weights of the intersection graph. This is only returned if
eweight1
is notNone
.- propslist of
PropertyMap
objects List of properties in the merged graph. This is only returned if props is not empty. Internal property maps are not included in this list.
- ug
See also
graph_merge
Merge the edge sets between two graphs.
graph_union
Union of the edge sets between two graphs.
graph_difference
Difference of the edge sets between two graphs.
graph_sym_difference
Symmetrcic difference of the edge sets between two graphs.
Notes
This algorithm is a wrapper around
graph_merge()
, and shares with it the same algorithmic complexity.Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
Examples
>>> g = gt.collection.ns["lesmis"] >>> u1 = gt.GraphView(g, efilt=np.random.random(g.num_edges()) < .5) >>> u2 = gt.GraphView(g, efilt=np.random.random(g.num_edges()) < .5) >>> u = gt.graph_intersection(u1, u2) >>> gt.graph_draw(u1, pos=g.vp._pos, output="gsub1_int.pdf") <...> >>> gt.graph_draw(u2, pos=g.vp._pos, output="gsub2_int.pdf") <...> >>> gt.graph_draw(u, pos=g.vp._pos, output="gint.pdf") <...>