GraphTheory
Contract
contract edge of a graph
Calling Sequence
Parameters
Options
Description
Examples
Contract(G, e, opts)
G
-
graph
e
edge of the graph
opts
(optional) one or more options as described below
multigraph = truefalse
mul : (optional) equation of the form multigraph=true or false
The Contract command contracts the specified edge of a graph. By default, all the loops and multiple edges are removed. By setting multigraph=true, the loops and multiple edges are preserved and the output is a weighted graph.
To contract multiple edges in a graph, use ContractSubgraph or use the foldl command.
with⁡GraphTheory:
with⁡SpecialGraphs:
G≔CompleteGraph⁡4
G≔Graph 1: an undirected graph with 4 vertices and 6 edge(s)
Contract⁡G,1,3
Graph 2: an undirected graph with 3 vertices and 3 edge(s)
Contract⁡G,1,3,multigraph=true
Graph 3: an undirected multigraph with 3 vertices, 5 edge(s), and 1 self-loop(s)
P≔PetersenGraph⁡
P≔Graph 4: an undirected graph with 10 vertices and 15 edge(s)
DrawGraph⁡P
Contract the five edges connecting the inner star to the outer pentagon to show K5.
G≔foldl⁡Contract,P,1,6,2,9,3,7,4,10,5,8
G≔Graph 5: an undirected graph with 5 vertices and 10 edge(s)
NumberOfVertices⁡G
5
IsClique⁡G
true
See Also
ContractSubgraph
DeleteEdge
DeleteVertex
foldl
Download Help Document