VertexContract[g,{v1,v2,…}]
contracts a collection of vertices v1, v2, … into a single vertex of the graph g.
VertexContract[g,{{v1,v2,…},…}]
contracts several collections of vertices.
VertexContract[{vw,…},…]
uses rules vw to specify the graph g.
VertexContract
VertexContract[g,{v1,v2,…}]
contracts a collection of vertices v1, v2, … into a single vertex of the graph g.
VertexContract[g,{{v1,v2,…},…}]
contracts several collections of vertices.
VertexContract[{vw,…},…]
uses rules vw to specify the graph g.
Details and Options
- VertexContract is also known as vertex identification.
- VertexContract[g,{v1,v2,…}] creates a new graph from g by removing all edges between vi and vj and merging them into the single vertex v1.
- VertexContract works with undirected graphs, directed graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (1)
Scope (7)
VertexContract works with undirected graphs:
VertexContract[[image], {1, 2}]VertexContract[[image], {1, 2}]VertexContract[[image], {1, 2}]VertexContract[[image], {1, 2}]Use rules to specify the graph:
VertexContract[{1 -> 3, 2 -> 1, 3 -> 6, 4 -> 6, 1 -> 5, 5 -> 4, 6 -> 1}, {1, 2}]Use patterns to specify a set of vertices:
VertexContract[[image], _ ? ((# < 4)&)]VertexContract works with large graphs:
GridGraph[{10, 10, 10, 10}];VertexCount[VertexContract[%, {1, 2}]]//TimingApplications (2)
Find the connectivity between communities in a network:
g = [image];com = FindGraphCommunities[g]VertexContract[g, com]List all possible vertex identifications between two RNA tree models to model RNA bonding:
g = [image];gs = VertexContract[g, #]& /@ Flatten[Table[{i, j}, {i, Range[4]}, {j, Range[5, 7]}], 1]Gather all isomorphic graphs into groups and show non-isomorphic trees:
gc = GatherBy[Map[{#, CanonicalGraph[#]}&, gs], Last];First /@ (First /@ #& /@ gc)Properties & Relations (2)
Using VertexReplace to contract vertices:
g = CycleGraph[5];VertexContract[g, {1, 2}]SimpleGraph@VertexReplace[g, 2 -> 1]EdgeContract can be computed using VertexContract:
g = WheelGraph[7];EdgeContract[g, {12, 34}]VertexContract[g, Flatten[List@@@{12, 34}]]Related Guides
Text
Wolfram Research (2014), VertexContract, Wolfram Language function, https://reference.wolfram.com/language/ref/VertexContract.html (updated 2015).
CMS
Wolfram Language. 2014. "VertexContract." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/VertexContract.html.
APA
Wolfram Language. (2014). VertexContract. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VertexContract.html
BibTeX
@misc{reference.wolfram_2026_vertexcontract, author="Wolfram Research", title="{VertexContract}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/VertexContract.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vertexcontract, organization={Wolfram Research}, title={VertexContract}, year={2015}, url={https://reference.wolfram.com/language/ref/VertexContract.html}, note=[Accessed: 13-June-2026]}