{-# LINE 1 "src/IGraph/Generators.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Generators
( full
, ErdosRenyiModel(..)
, erdosRenyiGame
, degreeSequenceGame
, rewire
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Marshal.Utils as C2HSImp
import Control.Monad (when)
import Data.Hashable (Hashable)
import Data.Serialize (Serialize)
import qualified Foreign.Ptr as C2HSImp
import IGraph
import IGraph.Mutable
import IGraph.Internal
{-# LINE 18 "src/IGraph/Generators.chs" #-}
import IGraph.Internal.Constants
{-# LINE 19 "src/IGraph/Generators.chs" #-}
import IGraph.Internal.Initialization
{-# LINE 20 "src/IGraph/Generators.chs" #-}
full :: (Int) -> (Bool) -> (Bool) -> IO ((IGraph))
full a2 a3 a4 =
allocaIGraph $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = C2HSImp.fromBool a3} in
let {a4' = C2HSImp.fromBool a4} in
full'_ a1' a2' a3' a4' >>= \res ->
addIGraphFinalizer a1'>>= \a1'' ->
return (a1'')
{-# LINE 27 "src/IGraph/Generators.chs" #-}
data ErdosRenyiModel = GNP Int Double
| GNM Int Int
erdosRenyiGame :: Graph d
=> ErdosRenyiModel
-> d
-> Bool
-> IO (LGraph d () ())
erdosRenyiGame (GNP n p) d self = do
gp <- igraphInit >> igraphErdosRenyiGame IgraphErdosRenyiGnp n p (isD d) self
unsafeFreeze $ MLGraph gp
erdosRenyiGame (GNM n m) d self = do
gp <- igraphInit >> igraphErdosRenyiGame IgraphErdosRenyiGnm n
(fromIntegral m) (isD d) self
unsafeFreeze $ MLGraph gp
igraphErdosRenyiGame :: (ErdosRenyi) -> (Int) -> (Double) -> (Bool) -> (Bool) -> IO ((IGraph))
igraphErdosRenyiGame a2 a3 a4 a5 a6 =
allocaIGraph $ \a1' ->
let {a2' = (fromIntegral . fromEnum) a2} in
let {a3' = fromIntegral a3} in
let {a4' = realToFrac a4} in
let {a5' = C2HSImp.fromBool a5} in
let {a6' = C2HSImp.fromBool a6} in
igraphErdosRenyiGame'_ a1' a2' a3' a4' a5' a6' >>= \res ->
addIGraphFinalizer a1'>>= \a1'' ->
return (a1'')
{-# LINE 47 "src/IGraph/Generators.chs" #-}
degreeSequenceGame :: [Int]
-> [Int]
-> IO (LGraph D () ())
degreeSequenceGame out_deg in_deg = do
out_deg' <- fromList $ map fromIntegral out_deg
in_deg' <- fromList $ map fromIntegral in_deg
gp <- igraphDegreeSequenceGame out_deg' in_deg' IgraphDegseqSimple
unsafeFreeze $ MLGraph gp
igraphDegreeSequenceGame :: (Vector) -> (Vector) -> (Degseq) -> IO ((IGraph))
igraphDegreeSequenceGame a2 a3 a4 =
allocaIGraph $ \a1' ->
(withVector) a2 $ \a2' ->
(withVector) a3 $ \a3' ->
let {a4' = (fromIntegral . fromEnum) a4} in
igraphDegreeSequenceGame'_ a1' a2' a3' a4' >>= \res ->
addIGraphFinalizer a1'>>= \a1'' ->
return (a1'')
{-# LINE 61 "src/IGraph/Generators.chs" #-}
rewire :: (Graph d, Hashable v, Serialize v, Eq v, Serialize e)
=> Int
-> LGraph d v e
-> IO (LGraph d v e)
rewire n gr = do
(MLGraph gptr) <- thaw gr
err <- igraphRewire gptr n IgraphRewiringSimple
when (err /= 0) $ error "failed to rewire graph!"
unsafeFreeze $ MLGraph gptr
igraphRewire :: (IGraph) -> (Int) -> (Rewiring) -> IO ((Int))
igraphRewire a1 a2 a3 =
(withIGraph) a1 $ \a1' ->
let {a2' = fromIntegral a2} in
let {a3' = (fromIntegral . fromEnum) a3} in
igraphRewire'_ a1' a2' a3' >>= \res ->
let {res' = fromIntegral res} in
return (res')
{-# LINE 73 "src/IGraph/Generators.chs" #-}
foreign import ccall safe "IGraph/Generators.chs.h igraph_full"
full'_ :: ((C2HSImp.Ptr (IGraph)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall safe "IGraph/Generators.chs.h igraph_erdos_renyi_game"
igraphErdosRenyiGame'_ :: ((C2HSImp.Ptr (IGraph)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (C2HSImp.CDouble -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))))
foreign import ccall safe "IGraph/Generators.chs.h igraph_degree_sequence_game"
igraphDegreeSequenceGame'_ :: ((C2HSImp.Ptr (IGraph)) -> ((C2HSImp.Ptr (Vector)) -> ((C2HSImp.Ptr (Vector)) -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))
foreign import ccall safe "IGraph/Generators.chs.h igraph_rewire"
igraphRewire'_ :: ((C2HSImp.Ptr (IGraph)) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))