random-cycle-0.1.0.0: src/RandomCycle/List.hs
module RandomCycle.List
( uniformPartition,
uniformPartitionThin,
uniformCyclePartition,
uniformCyclePartitionThin,
partitionLengths,
partitionFromBits,
)
where
import Control.Monad.Primitive (PrimMonad)
import qualified Data.Vector as V
import RandomCycle.List.Partition
import qualified RandomCycle.Vector as RV
import System.Random.Stateful (StatefulGen)
-- | Sample a cycle graph partition of '[0.. n-1]',
-- uniformly over the \(n!\) possibilities. The list implementation
-- is a convenenience wrapper around 'RandomCycle.Vector.uniformCyclePartition'.
uniformCyclePartition :: (PrimMonad m, StatefulGen g m) => Int -> g -> m [(Int, Int)]
uniformCyclePartition n g = do
v <- RV.uniformCyclePartition n g
pure $ V.toList v
-- | Sample a cycle graph partition of '[0.. n-1]',
-- uniformly over the set satisfying the conditions.
-- The list implementation is a convenenience wrapper around
-- 'RandomCycle.Vector.uniformCyclePartitionThin'.
uniformCyclePartitionThin ::
(PrimMonad m, StatefulGen g m) =>
Int ->
((Int, Int) -> Bool) ->
Int ->
g ->
m (Maybe [(Int, Int)])
uniformCyclePartitionThin maxit r n g = do
v <- RV.uniformCyclePartitionThin maxit r n g
pure $ V.toList <$> v