How to resolve the algorithm Dijkstra's algorithm step by step in the SAS programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Dijkstra's algorithm step by step in the SAS programming language

Table of Contents

Problem Statement

Dijkstra's algorithm, conceived by Dutch computer scientist Edsger Dijkstra in 1956 and published in 1959, is a graph search algorithm that solves the single-source shortest path problem for a graph with non-negative edge path costs, producing a shortest path tree.
This algorithm is often used in routing and as a subroutine in other graph algorithms.

For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost (i.e. the shortest path) between that vertex and every other vertex.

If the vertices of the graph represent cities and edge path costs represent driving distances between pairs of cities connected by a direct road,   Dijkstra's algorithm can be used to find the shortest route between one city and all other cities.
As a result, the shortest path first is widely used in network routing protocols, most notably:

The inputs to Dijkstra's algorithm are a directed and weighted graph consisting of 2 or more nodes, generally represented by:

A destination node is not specified. The output is a set of edges depicting the shortest path to each destination node.

You can use numbers or names to identify vertices in your program.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Dijkstra's algorithm step by step in the SAS programming language

Source code in the sas programming language

/* create SAS data set */
data Edges;
   input Start $ End $ Cost; 
   datalines;
a  b  7  
a  c  9  
a  f  14  
b  c  10  
b  d  15  
c  d  11  
c  f  2  
d  e  6  
e  f  9  
;

/* call OPTMODEL procedure in SAS/OR */
proc optmodel;
   /* declare sets and parameters, and read input data */
   set <str,str> LINKS;
   num cost {LINKS};
   read data Edges into LINKS=[start end] cost;
   set NODES = union {<i,j> in LINKS} {i,j};
   set SOURCES = {'a'};
   set SINKS = {'e'};
   /* <source,sink,order,from,to> */
   set <str,str,num,str,str> PATHS;

   /* call network solver */
   solve with network /
      shortpath=(source=SOURCES sink=SINKS) links=(weight=cost) out=(sppaths=PATHS);

   /* write shortest path to SAS data set */
   create data path from [source sink order from to]=PATHS cost[from,to];
quit;

/* print shortest path */
proc print data=path;
run;


  

You may also check:How to resolve the algorithm MD5 step by step in the Java programming language
You may also check:How to resolve the algorithm Exponentiation operator step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Panoramic programming language
You may also check:How to resolve the algorithm Read a file line by line step by step in the Haskell programming language
You may also check:How to resolve the algorithm Fermat pseudoprimes step by step in the Raku programming language