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
1
Issues
1
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
d4aa9e34
Commit
d4aa9e34
authored
Apr 01, 2017
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more generators
parent
f4b3a1b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
9 deletions
+49
-9
haskell-igraph.cabal
haskell-igraph.cabal
+2
-2
Generators.hs
src/IGraph/Generators.hs
+32
-5
Constants.chs
src/IGraph/Internal/Constants.chs
+6
-0
Graph.chs
src/IGraph/Internal/Graph.chs
+9
-2
No files found.
haskell-igraph.cabal
View file @
d4aa9e34
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
-- documentation, see http://haskell.org/cabal/users-guide/
name: haskell-igraph
name: haskell-igraph
version: 0.3.
0
version: 0.3.
1-dev
synopsis: Imcomplete igraph bindings
synopsis: Imcomplete igraph bindings
description: This is an attempt to create a complete bindings for the
description: This is an attempt to create a complete bindings for the
igraph<"http://igraph.org/c/"> library.
igraph<"http://igraph.org/c/"> library.
...
@@ -10,7 +10,7 @@ license: MIT
...
@@ -10,7 +10,7 @@ license: MIT
license-file: LICENSE
license-file: LICENSE
author: Kai Zhang
author: Kai Zhang
maintainer: kai@kzhang.org
maintainer: kai@kzhang.org
copyright: (c) 2016 Kai Zhang
copyright: (c) 2016
-2017
Kai Zhang
category: Math
category: Math
build-type: Simple
build-type: Simple
cabal-version: >=1.24
cabal-version: >=1.24
...
...
src/IGraph/Generators.hs
View file @
d4aa9e34
module
IGraph.Generators
module
IGraph.Generators
(
ErdosRenyiModel
(
..
)
(
ErdosRenyiModel
(
..
)
,
erdosRenyiGame
,
erdosRenyiGame
,
degreeSequenceGame
,
rewire
)
where
)
where
import
IGraph
import
Control.Monad
(
when
)
import
IGraph.Mutable
import
Data.Hashable
(
Hashable
)
import
IGraph.Internal.Graph
import
IGraph.Internal.Constants
import
IGraph
import
IGraph.Internal.Initialization
import
IGraph.Internal.Constants
import
IGraph.Internal.Data
import
IGraph.Internal.Graph
import
IGraph.Internal.Initialization
import
IGraph.Mutable
data
ErdosRenyiModel
=
GNP
Int
Double
data
ErdosRenyiModel
=
GNP
Int
Double
|
GNM
Int
Int
|
GNM
Int
Int
...
@@ -24,3 +30,24 @@ erdosRenyiGame (GNM n m) d self = do
...
@@ -24,3 +30,24 @@ erdosRenyiGame (GNM n m) d self = do
gp
<-
igraphInit
>>
igraphErdosRenyiGame
IgraphErdosRenyiGnm
n
gp
<-
igraphInit
>>
igraphErdosRenyiGame
IgraphErdosRenyiGnm
n
(
fromIntegral
m
)
(
isD
d
)
self
(
fromIntegral
m
)
(
isD
d
)
self
unsafeFreeze
$
MLGraph
gp
unsafeFreeze
$
MLGraph
gp
-- | Generates a random graph with a given degree sequence.
degreeSequenceGame
::
[
Int
]
-- ^ Out degree
->
[
Int
]
-- ^ In degree
->
IO
(
LGraph
D
()
()
)
degreeSequenceGame
out_deg
in_deg
=
do
out_deg'
<-
listToVector
$
map
fromIntegral
out_deg
in_deg'
<-
listToVector
$
map
fromIntegral
in_deg
gp
<-
igraphDegreeSequenceGame
out_deg'
in_deg'
IgraphDegseqSimpleNoMultiple
unsafeFreeze
$
MLGraph
gp
-- | Randomly rewires a graph while preserving the degree distribution.
rewire
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
Int
-- ^ Number of rewiring trials to perform.
->
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
src/IGraph/Internal/Constants.chs
View file @
d4aa9e34
...
@@ -28,3 +28,9 @@ import Foreign
...
@@ -28,3 +28,9 @@ import Foreign
{#enum igraph_erdos_renyi_t as ErdosRenyi {underscoreToCase}
{#enum igraph_erdos_renyi_t as ErdosRenyi {underscoreToCase}
deriving (Show, Read, Eq) #}
deriving (Show, Read, Eq) #}
{#enum igraph_rewiring_t as Rewiring {underscoreToCase}
deriving (Show, Read, Eq) #}
{#enum igraph_degseq_t as Degseq {underscoreToCase}
deriving (Show, Read, Eq) #}
src/IGraph/Internal/Graph.chs
View file @
d4aa9e34
...
@@ -54,6 +54,13 @@ igraphEdge g i = alloca $ \fr -> alloca $ \to -> do
...
@@ -54,6 +54,13 @@ igraphEdge g i = alloca $ \fr -> alloca $ \to -> do
{#fun igraph_full as ^ { +, `Int', `Bool', `Bool' } -> `IGraphPtr' #}
{#fun igraph_full as ^ { +, `Int', `Bool', `Bool' } -> `IGraphPtr' #}
{#fun igraph_erdos_renyi_game as ^ { +, `ErdosRenyi', `Int', `Double', `Bool'
{#fun igraph_erdos_renyi_game as ^ { +, `ErdosRenyi', `Int', `Double', `Bool'
, `Bool'} -> `IGraphPtr' #}
, `Bool' } -> `IGraphPtr' #}
{#fun igraph_degree_sequence_game as ^ { +, `VectorPtr', `VectorPtr'
, `Degseq' } -> `IGraphPtr' #}
{#fun igraph_rewire as ^ { `IGraphPtr', `Int', `Rewiring' } -> `Int' #}
{#fun igraph_isoclass_create as ^ { +, `Int', `Int', `Bool' } -> `IGraphPtr' #}
{#fun igraph_isoclass_create as ^ { +, `Int', `Int', `Bool' } -> `IGraphPtr' #}
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