GRSHORTESTPATH Find a shortest path between two nodes in the graph.
PATH = grShortestPath(NODES, EDGES, NODE1, NODE2, WEIGHTS)
NODES and EDGES defines the graph, NODE1 and NODE2 are indices of the
node extremities, and WEIGHTS is the set of weights associated to each
edge.
The function returns a set of node indices.
PATH = grShortestPath(NODES, EDGES, NODEINDS, WEIGHTS)
Specifies two or more points that must be traversed by the path, in the
specified order.
% Create a simple tree graph, and compute shortest path
[x y] = meshgrid([10 20 30], [10 20 30]);
nodes = [x(:) y(:)];
edges = [1 2;2 3;2 5;3 6; 4 5;4 7;5 8; 8 9];
drawGraph(nodes, edges)
axis equal; axis([0 40 0 40]);
drawNodeLabels(nodes, 1:9)
path = grShortestPath(nodes, edges, 1, 9);
% same as:
path = grShortestPath(nodes, edges, [1 9]);
See also
graphs, grFindMaximalLengthPath
Package: matgeom