%% Pick or Combine Multiple Graph Edges
% Use the second input of simplify to select a method that picks between multiple edges or combines multiple edges into one.
%
% Create a weighted multigraph. In this graph, five edges occur between node 3 and node 4, but the edges have random weights. View the edges table and plot the graph for reference.

G = graph([1 2 3 3 3 3 3 3 ],[2 3 1 4 4 4 4 4],randi(10,1,8));
G.Edges

%

plot(G,'EdgeLabel',G.Edges.Weight)

%
% The command simplify(G) keeps the first of the repeated edges. However, you can specify a different pick/combine method with the second input.
%
% The options for picking between multiple edges are: 'first' (default), 'last', 'min', and 'max'. Keep the repeated edge with maximum weight.

H_pick = simplify(G,'max');
plot(H_pick,'EdgeLabel',H_pick.Edges.Weight)

%
% The options for combining multiple edges into one are: 'sum' and 'mean'. Sum repeated edges together to produce a single edge with a larger weight.

H_comb = simplify(G,'sum');
plot(H_comb,'EdgeLabel',H_comb.Edges.Weight)

% Copyright 2012 The MathWorks, Inc.