Consider a directed graph that goes from the first node 1
to some end nodes (which no longer have outgoing edges). Each edge in the graph has a probability associated with it. Summing up the probabilities for each possible path to all possible end nodes, return 1
. (This means that we are guaranteed to reach one of the end nodes in the end.)
The problem would be simple if cycles did not exist on the chart. Unfortunately, rather confusing loops can occur on the graph, which can go through infinitely many times (the probability, of course, is multiplicative with each loop round).
Is there a general algorithm for finding probabilities for each end node?
A particularly unpleasant example:
We can represent the edges in the form of a matrix (the probability of transition from the row (node) x
to the row (node) y
is in the record (x,y)
)
{{0, 1/2, 0, 1/14, 1/14, 0, 5/14}, {0, 0, 1/9, 1/2, 0, 7/18, 0}, {1/8, 7/16, 0, 3/16, 1/8, 0, 1/8}, {0, 1, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}}
Or as a directed graph:
![enter image description here](https://fooobar.com//img/d50846dfa78d94162b6d419536fedf59.png)
Start node 1
blue, end nodes 5,6,7
are green. All edges are labeled with the probability of their intersection, starting with the node where they occur.
It has eight different paths from running node 1
to end nodes:
{{1/14, {1, 5}}, {5/14, {1, 7}}, {7/36, {1, 2, 6}}, {1/144, {1, 2, 3, 5}}, {1/144, {1, 2, 3, 7}}, {1/36, {1, 4, 2, 6}}, {1/1008, {1, 4, 2, 3, 5}}, {1/1008, {1, 4, 2, 3, 7}}}
(The designation for each path is {probability, sequence of visited nodes})
And there are five different cycles:
{{1/144, {2, 3, 1}}, {7/144, {3, 2}}, {1/2, {4, 2}}, {1/48, {3, 4, 2}}, {1/1008, {4, 2, 3, 1}}}
(The designation for cycles is {the probability of a cycle once, the sequence of nodes visited}).
If only these loops could be resolved to produce an efficient tree, similar to a graph, the problem would be solved.
Any hint on how to handle this?
I am familiar with Java, C ++ and C, so suggestions in these languages ββare preferable.