<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Archana Sridhar on Medium]]></title>
        <description><![CDATA[Stories by Archana Sridhar on Medium]]></description>
        <link>https://medium.com/@sridharchana?source=rss-d93edc71e182------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OKInUBBZJHTsDOYe</url>
            <title>Stories by Archana Sridhar on Medium</title>
            <link>https://medium.com/@sridharchana?source=rss-d93edc71e182------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:04:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sridharchana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[“Optimizing Network Paths: Applying the Bellman-Ford Algorithm for Advanced Routing Analytics”]]></title>
            <link>https://medium.com/@sridharchana/optimizing-network-paths-applying-the-bellman-ford-algorithm-for-advanced-routing-analytics-4e14375950b7?source=rss-d93edc71e182------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e14375950b7</guid>
            <dc:creator><![CDATA[Archana Sridhar]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 11:45:59 GMT</pubDate>
            <atom:updated>2023-08-29T16:52:43.411Z</atom:updated>
            <content:encoded><![CDATA[<p>The Bellman-Ford algorithm is a fundamental shortest path algorithm used in graph theory and network analysis. Named after its creators Richard Bellman and Lester Ford, it efficiently computes the shortest paths between a source vertex and all other vertices in a weighted graph, even when negative edge weights or cycles are present. By iteratively relaxing edges, the algorithm gradually refines distance estimates until optimal paths are obtained. This algorithm’s versatility and ability to handle various scenarios make it an essential tool for routing, network analytics, and resource allocation in diverse fields.</p><p><strong>Explore Bellman-Ford for directed graph shortest paths. It’s rooted in Bellman’s equation, pivotal in reinforcement learning and data science.</strong></p><p><strong>Bellman equation <br><em> V</em>(<em>x</em>) = max​[<em>f</em>(<em>x</em>,<em>a</em>)+<em>V</em>(<em>g</em>(<em>x</em>,<em>a</em>))]</strong></p><p>Here, <strong><em>V</em>(<em>x</em>)</strong> is the optimal value of the problem at state <em>x</em>,<strong> f(<em>x</em>,<em>u</em>)</strong> is the reward or cost of taking action <strong><em>a</em></strong> in state <strong><em>x</em></strong>; <strong><em>g</em>(<em>x</em>,<em>a</em>)</strong> is the next state that results from taking action <strong><em>a</em></strong> in state <strong><em>x</em></strong>; and max denotes the maximum over all possible actions <strong><em>a</em></strong>.</p><p>The Bellman-Ford algorithm utilizes this equation iteratively to find the shortest paths from the source vertex to all other vertices in a graph with possibly negative edge weights.</p><p>Bellman’s equation for minimization problems has “min” in place of “max.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*DF6AJTBB4CB9aUNRv4RAHQ.png" /></figure><p>Consider the above graph with the given weights.<br>The detailed steps are given: —</p><p>Step 1: Defining the Graph and Nodes:</p><p>The edges and nodes for the graph are defined as follows:</p><pre>edges = [(&#39;a&#39;, &#39;b&#39;, {&#39;weight&#39;: 4}),<br>         (&#39;a&#39;, &#39;d&#39;, {&#39;weight&#39;: 5}),<br>         (&#39;b&#39;, &#39;d&#39;, {&#39;weight&#39;: 1}),<br>         (&#39;b&#39;, &#39;e&#39;, {&#39;weight&#39;: 3}),<br>         (&#39;b&#39;, &#39;c&#39;, {&#39;weight&#39;: 2}),<br>         (&#39;d&#39;, &#39;b&#39;, {&#39;weight&#39;: 3}),<br>         (&#39;d&#39;, &#39;e&#39;, {&#39;weight&#39;: 5}),<br>         (&#39;d&#39;, &#39;c&#39;, {&#39;weight&#39;: 4}),<br>         (&#39;e&#39;, &#39;c&#39;, {&#39;weight&#39;: -5}),<br>         (&#39;c&#39;, &#39;a&#39;, {&#39;weight&#39;: 3})]<br><br>nodes = list(&#39;abcde&#39;)<br></pre><p>This defines the edges between nodes ‘a’, ‘b’, ‘c’, ‘d’, and ‘e’. Each edge has a weight associated with it.</p><p>Step 2: Initializing Matrices:</p><p>Matrices are initialized to store data about the graph:</p><pre>n = len(nodes)<br>idxs = list(np.arange(n))<br>i2s = dict(zip(idxs, nodes))<br>V = np.inf * np.ones(n)<br>V[nodes.index(&#39;e&#39;)] = 0<br>E = np.inf * np.ones((n, n))</pre><p>Here, V will hold the shortest distances, and E will store edge weights. The index mapping i2s maps indices to node labels.</p><p>Step 3: Setting Edge Weights:</p><p>Edge weights are extracted from the provided edges and assigned to matrix E:</p><pre>for edge in edges:<br>    u, v, weight = edge<br>    E[nodes.index(u), nodes.index(v)] = weight[&#39;weight&#39;]</pre><p>Step 4: Bellman-Ford Algorithm:</p><p>The Bellman-Ford algorithm is implemented to find the shortest distances and paths:</p><pre>def Bellman(E, V):<br>    value_new = True<br>    num_iterative = 0<br>    while value_new:<br>        num_iterative += 1<br>        value_new = False<br>        for i in range(V.size):<br>            for j in range(V.size):<br>                vij = E[i, j] + V[j]<br>                if vij &lt; V[i]:  # Compare vij with the current value V[i]<br>                    V[i] = vij  # Update V[i] with the smaller value<br>                    value_new = True<br>    return V, num_iterative</pre><p>This algorithm iterates through each node multiple times { (V.size — 1) iterations } and compares the distances through each edge to find the shortest paths.</p><p>Step 5: Printing Shortest Paths:</p><p>The function to print shortest paths is defined:</p><pre>def print_shortest_paths(E, V, v_first, i2s):<br>    for i in range(V.size):<br>        min_V = V[i]<br>        best_next = i<br>        for j in range(V.size):<br>            vij = min(E[i,j],E[i, j] + v_first[j])<br>            if vij &lt; min_V:<br>                min_V = vij<br>                best_next = j<br>                #print(&quot;------min_V&quot;)<br>        path = []<br>        current = i<br>        while current != best_next:<br>            path.append(i2s[current])<br>            current = best_next<br>        path.append(i2s[best_next])<br>        print(f&quot;{i2s[i]} --&gt; {i2s[best_next]} | Shortest Distance: {min_V} | Path: {&#39; -&gt; &#39;.join(path)}&quot;)</pre><p>Step 7: Running the Algorithm and Printing Results:</p><p>The algorithm is executed, and results are printed:</p><pre>v_first, num_iterative = Bellman(E.copy(), V.copy())<br>print(&#39;Iterations:&#39;, num_iterative)<br><br>print_shortest_paths(E.copy(), V.copy(), v_first.copy(), i2s)</pre><p>This code outputs the shortest distances and paths between nodes ‘a’, ‘b’, ‘c’, ‘d’, and ‘e’ using the provided edges and the Bellman-Ford algorithm.</p><p><strong>The Bellman-Ford algorithm is a versatile and widely used algorithm in the field of computer science and graph theory. It primarily deals with finding the shortest paths in a graph, but it has several applications beyond that. Here are some common applications of the Bellman-Ford algorithm:</strong></p><ol><li>Single-Source Shortest Paths: Finding the shortest paths from a single source to all other nodes in a weighted graph, even with negative edge weights.</li><li>Arbitrage Detection: Identifying profitable currency exchange sequences by detecting negative-weight cycles in exchange rate graphs.</li><li>Network Routing: Determining optimal paths for data transmission across routers or nodes in computer networks.</li><li>Traffic Engineering: Optimizing traffic routing to minimize congestion and delays by balancing load across the network.</li><li>Resource Allocation: Allocating resources efficiently, like in project scheduling or resource management.</li><li>Distance Vector Routing Protocols: Forming the basis of distance vector routing protocols in networking, aiding data flow decisions.</li><li>Robotics Path Planning: Planning the shortest path for robots through grids or maps while avoiding obstacles.</li><li>Critical Path Analysis: Calculating critical paths in project networks to identify tasks affecting project duration.</li><li>Recommendation Systems: Finding connections between users and items for personalized recommendations.</li></ol><p>The Bellman-Ford algorithm’s versatility makes it valuable in various fields such as networking, finance, logistics, and more. Its ability to handle negative edge weights and detect negative cycles gives it a unique edge in solving specific types of problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e14375950b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>