Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

random algorithm over all topological sorts of a DAG?

Does anyone know of a random algorithm for generating a topological sort of a DAG, where each invocation of the algorithm has a non-zero probability of generating every valid topological sort of the DAG.

It's crucial that the algorithm does not preclude any valid topological sort, because it's part of a larger algorithm that, given enough iterations, must be demonstrably capable of exploring all topological sorts of a given DAG.

Does anyone know if such an algorithm has been developed?

(Alternatively, if anyone knows of a reasonably efficient algorithm that's guaranteed to generate all topological sorts of a given DAG, I can probably tweak that to get what I need.)

like image 627
Christian Convey Avatar asked Jul 10 '12 19:07

Christian Convey


People also ask

Can a DAG have more than one topological sort?

Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time. Topological sorting has many applications especially in ranking problems such as feedback arc set. Topological sorting is possible even when the DAG has disconnected components.

Which algorithm is used for topological sorting?

Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering.

Does every DAG have a topological ordering?

Does any DAG have a topological order? The answer is YES.

What is topological sort in DAG?

A topological sort of a DAG is a linear ordering of all its vertices such that if contains an edge , then appears before in the ordering. For a DAG, we can construct a topological sort with running time linear to the number of vertices plus the number of edges, which is .


1 Answers

It helps to think in terms of what it means to say that you cover all possible topological sorts. During the topological sort, there is a point where you select a candidate to process from a subset of valid candidates, each of which is a valid choice. Depending on the way you implement the TS, it could be edge to follow from a set of edges each of which is a candidate (set of outgoing edges) or which node to select as the starting point (set of sinks/sources) or the randomly chosen start node.

What you want is to ensure that the selection process produces a distribution which does not show an overwhelming biased towards a particular subset of the candidates.

You can bias your selection process to achieve a more uniform distribution without running for infinite time. For example, you can assign a weight to each candidate of a set. Every time a candidate is selected you reduce the weight of that candidate by an amount "X" and increase the weight of the other candidates by an amount "X/(k-1)" where k is the size of the set of candidate set. This will result in a greater chance that a candidate which was not selected is selected in the next iteration, and result in a quicker convergence to a more uniform distribution.

like image 170
VSOverFlow Avatar answered Oct 07 '22 18:10

VSOverFlow