Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^13: Finding All Paths From a Graph From a Given Source and End Node

by BrowserUk (Pope)
on May 13, 2011 at 21:32 UTC ( #904736=note: print w/replies, xml ) Need Help??


in reply to Re^12: Finding All Paths From a Graph From a Given Source and End Node
in thread Finding All Paths From a Graph From a Given Source and End Node

I have a network containing about 2500 edges (directed) and I am looking at being able to work out all the routes downstream from a given beginning node.

Hm. What is your terminating condition?

A directed graph can contain loops:

a->b->c ^ | | v e<-d

If your starting node is (a), when do you decide you've reach the (an) end?

Every time around the b->c->d->e->b loop, could be seen as another route. The only logical basis I can see for breaking that impasse is a rule along the lines of "Stop when there is no possibility of reaching a so far unvisited node. And that could be quite difficult to program efficiently.

As so often, more info required?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^13: Finding All Paths From a Graph From a Given Source and End Node
  • Download Code

Replies are listed 'Best First'.
Re^14: Finding All Paths From a Graph From a Given Source and End Node
by eMBR_chi (Acolyte) on May 21, 2011 at 17:37 UTC

    Hi, BrowserUK,

    Sorry for the delayed reply. Have been inundated with work these two weeks. I just got some breathing space.

    To the question of terminating condition: The network is built from biodegradation reactions where, in A->B, B is the result of some reaction from A and the edge represents enzymes catalysing such a reaction. The source of the information is also such that most of the reaction paths have logical end points.

    The terminating situation will be when the path ends and there is no possibility of futher elongation along the path of interest.

    Example: J->K ^ | A->B->C->D->E ^ | | v H<-G

    A->B->C->D->E or A->B->C->D->G->H->C->J->K, would be correctly admissible in the resulting path.

    The edge between C and D should not be allowed again (as in that loop) seeing that in real life that enzyme would already be in the system and need not be captured again. However C as a node could be captured again (eg C->J). The important factor in the resulting pathways should be the edges. An earlier captured 'node-edge-node' should not be captured again, until the the path logically ends (without a possibility of further elongation).

    I hope the information supplied is sufficiently clear and helpful.

    Thank you so very much.

      The network is built from biodegradation reactions where, in A->B, B is the result of some reaction from A and the edge represents enzymes catalysing such a reaction. ...

      Hm. That suggests that having transitioned from the A state to the B state, you cannot go backwards to the A state.

      But then you have two sentences that have an overriding termination (or perhaps extension) criteria:

      The terminating situation will be when the path ends and there is no possibility of futher elongation along the path of interest. ...

      An earlier captured 'node-edge-node' should not be captured again, until the the path logically ends (without a possibility of further elongation).

      And in your example, having transitioned from c-d, the reaction(s) can find their way back to the c state; and then leave via a different route.

      Your path:A->B->C->D->G->H->C->J->K

      So my question is, if the reaction can go from c-d once; and can find its way back to c; why can it not transition c-d a second time?

      Which would make the path a-b-c-d-g-h-c-d-e an elongation of the path you've identified as legitimate: A->B->C->D->E

      Thinking, I hope logically, about a subject I know next to nothing about, I considered the possibility that whatever enzymes are in the original mix, when the C state occures it preferentially reacts with whichever enzyme(s) are required to transition to state D.

      And in doing so, depletes the mix of that(those) enzymes. Which means that when the mix arrives at the C state a second time, those enzymes are no longer present so it can now react with other enzymes that cause it to transition to state J.

      Is that a viable, even if technically inaccurate, model of what goes on?

      If so, I think an efficient solution is possible.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Oh Great!

        I appear to have used the word 'elongation' in a somewhat confusing manner. I didn't consider the fact that A->B->C->G->H->C->D->E is actually an elongation of A->B->C->D->E. But the intended meaning is that having arrived at E, if there is nothing else beyond E to which the path should go, then it ends

        And! The focus of the work is to list the possible paths from a given node, without getting stuck in a loop somewhere. This would mean that for the hypothetical example we are using here the following paths should result:

        a. A->B->C->D->E

        b. A->B->C->J->K

        c. A->B->C->D->G->H->C->J->K

        And! Yes. Your model of what is going on is so very viable.

        Of course we all would rather like to take any of the short routes. In nature however, the shortest routes sometimes are not the best and the objective here is to outline all the possible routes; and number them appropriately 'route1, route2, route3...', affording one the chance to look closely at each route and see its workability.

        Thanks a lot for your time. Its good to hear of a possible solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://904736]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2021-03-05 03:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (109 votes). Check out past polls.

    Notices?