Results 1 to 7 of 7

Thread: Retrieve many paths on a graph

  1. #1
    Join Date
    Jun 2009
    Posts
    87

    Retrieve many paths on a graph

    I would like to retrieve the number of paths between any pair of nodes on a graph. I use the Floyd-Warshall algo:

    Code:
     // i and j are the start-finish vertices and k is intermediate vertices 
    for ( k = 0 ; k < n; k++ ) {
    			 for ( i = 0 ; i < n; i++ )
    			 {
    				 for ( j = 0 ; j < n; j++ )
    				 {
    
     dist [ i ] [ j ] = Math. min ( dist [ i ] [ j ] , dist [ i ] [ k ] + dist [ k ] [ j ] ) ;
     ....}
    }
     }
    How can I retrieve the number of these paths?

  2. #2
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Retrieve many paths on a graph

    Begin by analyzing the algorithm of Floyd-Warshall. Explain your problem clearly because I do not see the difficulty. What is currently the result of your program?

  3. #3
    Join Date
    Jun 2009
    Posts
    87

    Re: Retrieve many paths on a graph

    In fact in the input of my program I have an n x n matrix containing the weights between 2 peaks (dist[i][j]=..) and my goal is both to seek the path + runs between couples peaks but also to retrieve the number of paths that connect them.

    for now my code allows me to retrieve only the weight corresponding to the shortest path (in dist[i][j]) without the number of paths.

    Code:
    public double[][] getMinLenghts() {
     
    //i and j are the start-finish vertices and k vertices is intermediate
    // n is the number of peaks on the graph
     
    for (k = 0; k < n; k++) {
    			for (i = 0; i < n; i++)
    			{
    				for (j = 0; j < n; j++)
    				{
     
    //Floyd Warshall Algo 
    dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
    ....}
    }
    }
     
    return dist;
    }

  4. #4
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Retrieve many paths on a graph

    Without thinking much to your problem, a recursive method should allow to calculate the number of paths. Each new point is added to a list, which is duplicated at each intersection. If the path leading to the finish, then you list ranges from the list of possible paths. But, you'll have to add data into your template to mark the points where you're already past. We must prevent endless cycles.

  5. #5
    Join Date
    Nov 2008
    Posts
    1,221

    Re: Retrieve many paths on a graph

    Beware, your application and your data has little in common. Floyd-Warshall is to discover the shortest distance, while you want the number of paths. Do you want also to mention the cycles? Try to use the API JGraphT very interesting for your case.

  6. #6
    Join Date
    Jun 2009
    Posts
    87

    Re: Retrieve many paths on a graph

    No, actually I do not want to count the rings. I already have a library that implements Dijkstra and gives the number of paths through trees but it is slow to load and that's why I thought of Floyd-Warshall.

  7. #7
    Join Date
    Nov 2008
    Posts
    1,185

    Re: Retrieve many paths on a graph

    I do not understand at all your problem. Since you want a list of all possible paths, why do you use an algorithm for finding the shortest (or one of the shortest) path? You need an algorithm of "brute force" that will make all possible combinations, and it comes back to my idea posted a little earlier.

Similar Threads

  1. How to move dirt paths in FrontierVille?
    By $Daiwik$ in forum Video Games
    Replies: 4
    Last Post: 09-02-2011, 10:11 AM
  2. Mapped drives vs. UNC paths
    By Jeff Johnson in forum Windows Server Help
    Replies: 10
    Last Post: 11-12-2009, 01:16 AM
  3. How to eliminate previous RUN commands and paths?
    By Dipu in forum Operating Systems
    Replies: 4
    Last Post: 05-03-2009, 02:24 PM
  4. CMD and UNC Paths in Login Script
    By David in forum Windows Server Help
    Replies: 6
    Last Post: 10-11-2005, 12:25 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,719,020,737.03366 seconds with 17 queries