Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-igraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-igraph
Commits
d8d7f6b0
Commit
d8d7f6b0
authored
Jun 07, 2018
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rewireEdges
parent
1987cba3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
2 deletions
+24
-2
Generators.chs
src/IGraph/Algorithms/Generators.chs
+24
-2
No files found.
src/IGraph/Algorithms/Generators.chs
View file @
d8d7f6b0
...
@@ -8,6 +8,7 @@ module IGraph.Algorithms.Generators
...
@@ -8,6 +8,7 @@ module IGraph.Algorithms.Generators
, ErdosRenyiModel(..)
, ErdosRenyiModel(..)
, erdosRenyiGame
, erdosRenyiGame
, degreeSequenceGame
, degreeSequenceGame
, rewireEdges
, rewire
, rewire
) where
) where
...
@@ -15,6 +16,7 @@ import Data.Serialize (Serialize)
...
@@ -15,6 +16,7 @@ import Data.Serialize (Serialize)
import Data.Singletons (SingI, Sing, sing, fromSing)
import Data.Singletons (SingI, Sing, sing, fromSing)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO)
import qualified Data.Map.Strict as M
import qualified Data.Map.Strict as M
import Control.Monad.Primitive (RealWorld)
import qualified Foreign.Ptr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Foreign
import Foreign
...
@@ -75,8 +77,11 @@ ring n = unsafePerformIO $ do
...
@@ -75,8 +77,11 @@ ring n = unsafePerformIO $ do
, `Bool'
, `Bool'
} -> `CInt' void- #}
} -> `CInt' void- #}
data ErdosRenyiModel = GNP Int Double
data ErdosRenyiModel = GNP Int Double -- ^ G(n,p) graph, every possible edge is
| GNM Int Int
-- included in the graph with probability p.
| GNM Int Int -- ^ G(n,m) graph, m edges are selected
-- uniformly randomly in a graph with n
-- vertices.
erdosRenyiGame :: forall d. SingI d
erdosRenyiGame :: forall d. SingI d
=> ErdosRenyiModel
=> ErdosRenyiModel
...
@@ -115,6 +120,22 @@ degreeSequenceGame out_deg in_deg = do
...
@@ -115,6 +120,22 @@ degreeSequenceGame out_deg in_deg = do
, castPtr `Ptr Vector', castPtr `Ptr Vector', `Degseq'
, castPtr `Ptr Vector', castPtr `Ptr Vector', `Degseq'
} -> `CInt' void- #}
} -> `CInt' void- #}
-- | Rewire the edges of a graph with constant probability.
rewireEdges :: MGraph RealWorld d v e
-> Double -- ^ The rewiring probability a constant between zero and
-- one (inclusive).
-> Bool -- ^ whether loop edges are allowed in the new graph, or not.
-> Bool -- ^ whether multiple edges are allowed in the new graph.
-> IO ()
rewireEdges gr p loop multi = igraphRewireEdges (_mgraph gr) p loop multi
{#fun igraph_rewire_edges as ^
{ `IGraph'
, `Double'
, `Bool'
, `Bool'
} -> `CInt' void- #}
-- | Randomly rewires a graph while preserving the degree distribution.
-- | Randomly rewires a graph while preserving the degree distribution.
rewire :: (Serialize v, Ord v, Serialize e)
rewire :: (Serialize v, Ord v, Serialize e)
=> Int -- ^ Number of rewiring trials to perform.
=> Int -- ^ Number of rewiring trials to perform.
...
@@ -125,3 +146,4 @@ rewire n gr = do
...
@@ -125,3 +146,4 @@ rewire n gr = do
igraphRewire (_mgraph gr') n IgraphRewiringSimple
igraphRewire (_mgraph gr') n IgraphRewiringSimple
unsafeFreeze gr'
unsafeFreeze gr'
{#fun igraph_rewire as ^ { `IGraph', `Int', `Rewiring' } -> `CInt' void-#}
{#fun igraph_rewire as ^ { `IGraph', `Int', `Rewiring' } -> `CInt' void-#}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment