All Unique Paths In A Directed Acyclic Graph, In Randomized Order, Via Python Generator?
Solution 1:
Please note that you're contradicting yourself: you want output to be "strictly unordered", but you have no state or memory for the sequence. This is simply not possible via information theory. However, if your goal is simply to have a "shuffle" -- a different sequence that a casual observer won't recognize as a predetermined sequence, then you have a chance.
First, determine your choice points and sizes. For instance, your choices above are [1, 2, 3] x [5, 6, 7]. This gives you 3*3 = 9 paths to generate. Let's add a third choice for illustration, a [T, F] on the end. This gives 3*3*2 = 18 paths.
Now, use your favorite "perfect sequence generator" to create a simple function for you. I'm assuming that something int he RNG process is allowed to recall the previous value or seed. For ridiculous simplicity, let's use a trivial linear sequence f(n) = f(n-1) + 5 (mod 18)
. This will give the sequence 0 5 10 15 2 7 12 17 ...
Now have your path generator call this function on each iteration. Simply convert the returned "random" number to digits in the given base sequence -- 3|3|2 in this case. Let's look at the value 7, taking the conversion from left to right, using the bases in order:
7 divmod 3 => mod1, quotient 22 divmod 3 => mod2, quotient 00 divmod 2 => mod0
Thus, you choose the path with elements 1, 2, 0 of your three choice arrays. The resulting path is (chosen nodes in bold):
2 4 6 8 T
Is that clear? Does it solve your problem?
Post a Comment for "All Unique Paths In A Directed Acyclic Graph, In Randomized Order, Via Python Generator?"