0% found this document useful (0 votes)
46 views

Experiment Name: Name: Tushar Shingade Roll No: 4253 Batch: B-3 Program

The document describes an experiment that implements a shortest path algorithm to find the shortest path between two nodes in a directed and undirected graph with 6 nodes and 11 edges. It creates the graphs, finds the shortest path from node 1 to node 6 using graphshortestpath, and then colors the nodes and thickens the edges of the shortest path in red to highlight it.

Uploaded by

Adib Shaikh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Experiment Name: Name: Tushar Shingade Roll No: 4253 Batch: B-3 Program

The document describes an experiment that implements a shortest path algorithm to find the shortest path between two nodes in a directed and undirected graph with 6 nodes and 11 edges. It creates the graphs, finds the shortest path from node 1 to node 6 using graphshortestpath, and then colors the nodes and thickens the edges of the shortest path in red to highlight it.

Uploaded by

Adib Shaikh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment Name: Write a program for Implementation of Shortest Path Algorithm Name: Tushar Shingade Roll No: 4253

Batch: B-3 Program:

clc; clear all; close all; %% Create and view a directed graph with 6 nodes and 11 edges. W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21]; DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W);

%% Finding the Shortest Path in an Undirected Graph %Create and view an undirected graph with 6 nodes and 11 edges. UG = tril(DG + DG'); %% h = view(biograph(UG,[],'ShowArrows','off','ShowWeights','on')); %% Find the shortest path in the graph from node 1 to node 6. [dist,path,pred] = graphshortestpath(UG,1,6,'directed',false); %% Mark the nodes and edges of the shortest path by coloring them red and % increasing the line width. set(h.Nodes(path),'Color',[1 0.4 0.4]); fowEdges = getedgesbynodeid(h,get(h.Nodes(path),'ID')); revEdges = getedgesbynodeid(h,get(h.Nodes(fliplr(path)),'ID')); edges = [fowEdges;revEdges]; set(edges,'LineColor',[1 0 0]); set(edges,'LineWidth',1.5);

Output:

You might also like