simplify

Collapses parallel edges and removes self-loops of a graph.

Category: Mathematics > Graph and Network Algorithms

Syntax

H = simplify(G)

Keeps one edge for each pair of nodes and drops self-loops.

H = simplify(G, 'min')

When edges merge, keeps the smallest weight. Other choices: 'max', 'sum', 'mean', 'first', 'last'.

Description

A multigraph has several edges between the same pair of nodes. simplify merges each such group into a single edge, and when weights exist it combines them with the chosen rule, for example summing the capacities of parallel pipes. Edges that join a node to itself are removed.

Check whether it is needed with ismultigraph.

Input arguments

G
A graph or digraph, possibly with parallel edges.
pickWeight
How to combine the weights of edges that merge.

Output arguments

H
A simple graph with the same nodes.

Example

Detecting a multigraph first

G = graph([1 1 2], [2 2 3], [1 2 3]);
ismultigraph(G)
edgecount(G, 1, 2)
Output
ans = logical
   1
ans = 2

In MATLAB, simplify(G, 'sum') would merge the two edges between nodes 1 and 2 into one of weight 3.

Notes

In MatLivre, simplify is available for symbolic expressions only. Calling it on a graph reports an error, so the example uses the related checks ismultigraph and edgecount instead.

See also

ismultigraph edgecount graph rmedge