Editing a graph.

1 visualización (últimos 30 días)
Lewis Waswa
Lewis Waswa el 7 de Jul. de 2023
Editada: Aniketh el 8 de Jul. de 2023
I have a graph with about 115 nodes, all differently interconnected.
I would like to do two things: Plot the directed graph illustrating the connection between the nodes. And to return the longest path on the graph.
B=A(1:115,:);
G = digraph(B(:,1),B(:,2));
%layout(G,"force")
plot(G, "NodeFontSize",8,"MarkerSize",6);
The code provides me with a directed graph but it is too sparse. How can I standardize the distance between nodes and make it more compact? and secondly, how can I calculate the longest path?
Kindly assist.

Respuestas (1)

Aniketh
Aniketh el 8 de Jul. de 2023
Editada: Aniketh el 8 de Jul. de 2023
Hi Lewis, MATLAB provides options to change the strucure through the layout function. You can check out this page for more details. You could try out 'force' or 'subspace' arguments, see what works best for your case.
In case this is still too sparse for the graph you are implementing one method I would suggest would be to manually normalize the values in the graph while plotting and unnormalize right after, should be an easy enough workaround for the illustration part.
For the second part,assuming you want the longest distance 'on' the graph(longest edge) and not the distance between any two nodes, because that could become a NP hard problem,
Here is how you could do that:
distances = distances(G);
longest_path_length = max(distances(:));
longest_path = shortestpath(G, 1, numel(G.Nodes));

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by