duplicate_vertices#
- graph_tool.generation.duplicate_vertices(g, dup, self_loops=False)[git][source]#
Duplicate the vertices of a graph.
- Parameters:
- g
Graph Graph to be modified.
- dup
VertexPropertyMap Scalar vertex property map with the number of copies of every vertex after the duplication (including the original vertex), which must be at least one.
- self_loops
bool(optional, default:False) If
True, self-loops are kept.
- g
- Returns:
- b
VertexPropertyMap Original vertex of every vertex of the duplicated graph.
- b
See also
corrupt_graphRandom removal and addition of edges
generate_duplication_divergenceDuplication-divergence model
generate_partial_duplicationPartial duplication model
graph_productGraph products
Notes
Every vertex \(v\) is replaced by \(d_v\) copies, where \(d_v\) is
dup[v], and two copies of vertices \(u\) and \(v\) are adjacent if and only if \(u\) and \(v\) are adjacent in the original graph, with the same multiplicity. Hence the copies of a vertex with a self-loop are adjacent to each other, and, ifself_loops == True, have a self-loop each; otherwise all self-loops are removed.The algorithm runs in time \(O(V + E)\), where \(V\) and \(E\) are the numbers of vertices and edges after the duplication.
Examples
>>> g = gt.collection.data["karate"].copy() >>> print(g) <Graph object, undirected, with 34 vertices and 78 edges, 1 internal vertex property, 2 internal graph properties, at 0x...> >>> b = gt.duplicate_vertices(g, g.new_vp("int", val=10)) >>> print(g) <Graph object, undirected, with 340 vertices and 7800 edges, 1 internal vertex property, 2 internal graph properties, at 0x...>
The graph obtained by duplicating every vertex of a cycle is drawn as follows, with the copies of every vertex in the same color:
>>> g = gt.circular_graph(6) >>> b = gt.duplicate_vertices(g, g.new_vp("int", val=2)) >>> cmap = matplotlib.colors.ListedColormap( ... ["#9bbedc", "#f28c8e", "#a6d7a4", "#cba6d1", "#ffbf7f", ... "#ffff99"]) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, ... vcmap=cmap, output="duplicate_vertices-cycle.pdf") <...>
Cycle \(C_6\) with two copies of every vertex. The vertex colors indicate the vertices of the cycle of which they are copies.#
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.