Code Examples
  Home arrow Code Examples arrow Page 3 - Critical Paths
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Critical Paths
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-06-01

    Table of Contents:
  • Critical Paths
  • The problem and translating it
  • The solution
  • The code snippet

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Critical Paths - The solution


    (Page 3 of 4 )

    It is important to note that here we have no circles in the graph. Considering this, we can apply with a little modification the algorithm we used to calculate the shortest road inside a graph with no circle inside it. Yes, you are right; it is the topological order-based technique.

    Here it is a graph drawn so that you can see and understand this better:

    -->Image Courtesy of Kátai Zoltán- Introduction to Graphs<--

    Practically, we are going to invert the topological order shortest-path algorithm and query for the longest road. You remember that the topological sort allowed us to order the vertexes in a way that all of the edges were directed from the left to the right.

    This way we could just follow with the edges in this order, to perform an approximation with each edge. We start from the root vertex of course. If we follow this principle, by the time we arrive at a vertex, we've already performed approximations through all of its incoming edges, and now we will have the shortest road from the root to this vertex.

    This is possible because the shortest path's sub-road is also the shortest road. So now, we will invert the statement, and instead of searching for the minimal distance between the source and the outgoing edges of a vertex, we will search for the maximum distance. From this, we will find out the longest road from the drain.

    We invert the graph, calculate the maximum length, and now we will get the longest roads from the source. For all the distances for which we did not yet calculate the maximum distance, we will have inside this two arrays minus one. The arrays are named intuitively the Longest Road Drain (lr_drain) and the Longest Road Source (lr_source).

    Our function will return as a result the maximum road value and generate the roads through the maximum leads within some additional arrays. There will be one for the normal call and one for the inverse graph call.

    In the case of both calls we will find out the same maximum road length; what differs is only the shortest roads between the stations of the critical path. Also, from the first call, we will find out the longest road path as well. The second call on the inverse is only required to find out the earliest time possible to start a job.

    The algorithm itself is a combination of the depth search algorithm and the topological order-based technique to find out the shortest (now the longest) road inside a graph. Instead of first building the topological order and later using it, we will make the approximation as soon as we get the node, so we do not need to store it.

    Furthermore, we save any preliminary results in the longsetroad array, so we will call the recursion only if, for that vertex, we have received approximation yet. This will mean that, in that index, the array is minus one. This way we will approximate with each edge at most once, and ensure that we can save the vertex, through we polished our maximum road a little in the nextCritNode array. All of this will become clearer as soon as you read the next page.  

    More Code Examples Articles
    More By Gabor Bernat


     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek