%% Edges Along Paths
% The second output argument of allpaths returns the edges that are along each path. This is particularly useful for multigraphs, where the edge index is required to uniquely identify the edges on the path.
%
% Create a directed multigraph with eight nodes and 18 edges. Specify names for the nodes. Plot the graph with labeled nodes and edges.

s = [1 1 2 2 3 3 2 2 4 6 8 6 6 7 3 3 5 3];
t = [2 3 1 3 2 1 4 4 6 2 6 7 8 8 5 5 7 7];
names = {'A','B','C','D','E','F','G','H'};
G = digraph(s,t,[],names);
p = plot(G,'EdgeLabel',1:numedges(G));

%
% Calculate all paths between node A and node H. Specify two output arguments to also return the edge indices for edges along each path.

[paths,edgepaths] = allpaths(G,'A','H');

% View the nodes and edges along the first path.

paths{1}
edgepaths{1}

% Highlight the nodes and edges along the first path.

highlight(p,'Edges',edgepaths{1},'EdgeColor','r','LineWidth',1.5,'NodeColor','r','MarkerSize',6)

%
% Copyright 2020 The MathWorks, Inc.