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
2
Merge Requests
2
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
f2bcfee7
Commit
f2bcfee7
authored
9 years ago
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more modules
parent
446c2c8c
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
226 additions
and
17 deletions
+226
-17
Structure.chs.c
cbits/Structure.chs.c
+22
-0
haskell-igraph.cabal
haskell-igraph.cabal
+15
-2
IGraph.hs
src/IGraph.hs
+3
-0
Graphics.hs
src/IGraph/Exporter/Graphics.hs
+31
-0
Generators.hs
src/IGraph/Generators.hs
+27
-0
Constants.chs
src/IGraph/Internal/Constants.chs
+3
-0
Graph.chs
src/IGraph/Internal/Graph.chs
+4
-0
Isomorphism.chs
src/IGraph/Internal/Isomorphism.chs
+16
-0
Structure.chs
src/IGraph/Internal/Structure.chs
+11
-0
Isomorphism.hs
src/IGraph/Isomorphism.hs
+23
-0
Layout.hs
src/IGraph/Layout.hs
+2
-2
Motif.hs
src/IGraph/Motif.hs
+45
-0
Structure.hs
src/IGraph/Structure.hs
+18
-0
test.hs
src/test.hs
+5
-12
stack.yaml
stack.yaml
+1
-1
No files found.
cbits/Structure.chs.c
View file @
f2bcfee7
#include "IGraph/Internal/Structure.chs.h"
int
__c2hs_wrapped__igraph_personalized_pagerank
(
const
igraph_t
*
graph
,
igraph_pagerank_algo_t
algo
,
igraph_vector_t
*
vector
,
igraph_real_t
*
value
,
const
igraph_vs_t
*
vids
,
igraph_bool_t
directed
,
igraph_real_t
damping
,
igraph_vector_t
*
reset
,
const
igraph_vector_t
*
weights
,
void
*
options
)
{
return
igraph_personalized_pagerank
(
graph
,
algo
,
vector
,
value
,
*
vids
,
directed
,
damping
,
reset
,
weights
,
options
);
}
int
__c2hs_wrapped__igraph_pagerank
(
const
igraph_t
*
graph
,
igraph_pagerank_algo_t
algo
,
igraph_vector_t
*
vector
,
...
...
This diff is collapsed.
Click to expand it.
haskell-igraph.cabal
View file @
f2bcfee7
...
...
@@ -17,6 +17,10 @@ build-type: Simple
extra-source-files: cbits/haskelligraph.c
cabal-version: >=1.22
Flag graphics
Description: Enable graphics output
Default: False
library
exposed-modules:
IGraph.Internal.Initialization
...
...
@@ -25,6 +29,7 @@ library
IGraph.Internal.Data
IGraph.Internal.Graph
IGraph.Internal.Attribute
IGraph.Internal.Isomorphism
IGraph.Internal.Selector
IGraph.Internal.Structure
IGraph.Internal.Clique
...
...
@@ -34,12 +39,20 @@ library
IGraph.Mutable
IGraph.Clique
IGraph.Structure
IGraph.Isomorphism
IGraph.Community
IGraph.Read
IGraph.Motif
IGraph.Layout
IGraph.Generators
IGraph.Exporter.GEXF
-- other-modules:
-- other-extensions:
if flag(graphics)
exposed-modules: IGraph.Exporter.Graphics
if flag(graphics)
build-depends: diagrams-lib, diagrams-svg
build-depends:
base >=4.0 && <5.0
, bytestring >=0.9
...
...
This diff is collapsed.
Click to expand it.
src/IGraph.hs
View file @
f2bcfee7
...
...
@@ -48,6 +48,7 @@ data LGraph d v e = LGraph
class
MGraph
d
=>
Graph
d
where
isDirected
::
LGraph
d
v
e
->
Bool
isD
::
d
->
Bool
nNodes
::
LGraph
d
v
e
->
Int
nNodes
(
LGraph
g
_
)
=
igraphVcount
g
...
...
@@ -107,9 +108,11 @@ class MGraph d => Graph d where
instance
Graph
U
where
isDirected
=
const
False
isD
=
const
False
instance
Graph
D
where
isDirected
=
const
True
isD
=
const
True
mkGraph
::
(
Graph
d
,
Hashable
v
,
Read
v
,
Eq
v
,
Show
v
,
Show
e
)
=>
(
Node
,
Maybe
[
v
])
->
([
Edge
],
Maybe
[
e
])
->
LGraph
d
v
e
...
...
This diff is collapsed.
Click to expand it.
src/IGraph/Exporter/Graphics.hs
0 → 100644
View file @
f2bcfee7
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
module
IGraph.Exporter.Graphics
(
renderGraph
,
graphToDiagram
)
where
import
Diagrams.Prelude
import
Diagrams.Backend.SVG.CmdLine
import
IGraph
import
IGraph.Exporter.GEXF
renderGraph
::
FilePath
->
Double
->
Double
->
LGraph
d
NodeAttr
EdgeAttr
->
IO
()
readerGraph
out
gr
=
renderSVG
out
(
Dims
w
h
)
$
graphToDiagram
gr
graphToDiagram
::
Graph
d
=>
LGraph
d
NodeAttr
EdgeAttr
->
Diagram
B
graphToDiagram
gr
=
position
(
map
drawNode
(
nodes
gr
))
<>
mconcat
(
map
drawEdge
(
edges
gr
))
where
drawNode
x
=
(
_positionX
nattr
^&
_positionY
nattr
,
circle
(
_size
nattr
)
#
lwO
0
#
fcA
(
_nodeColour
nattr
)
)
where
nattr
=
nodeLab
gr
x
drawEdge
(
from
,
to
)
=
fromVertices
[
_positionX
nattr1
^&
_positionY
nattr1
,
_positionX
nattr2
^&
_positionY
nattr2
]
where
eattr
=
edgeLab
gr
(
from
,
to
)
nattr1
=
nodeLab
gr
from
nattr2
=
nodeLab
gr
to
{-# INLINE graphToDiagram #-}
This diff is collapsed.
Click to expand it.
src/IGraph/Generators.hs
0 → 100644
View file @
f2bcfee7
module
IGraph.Generators
(
erdosRenyiGame
)
where
import
IGraph
import
IGraph.Mutable
import
IGraph.Internal.Graph
import
IGraph.Internal.Constants
import
IGraph.Internal.Initialization
data
ErdosRenyiModel
=
GNP
|
GNM
erdosRenyiGame
::
Graph
d
=>
ErdosRenyiModel
->
Int
-- ^ n
->
Double
-- ^ p or m
->
d
-- ^ directed
->
Bool
-- ^ self-loop
->
IO
(
LGraph
d
()
()
)
erdosRenyiGame
model
n
p_or_m
d
self
=
do
gp
<-
igraphInit
>>
igraphErdosRenyiGame
model'
n
p_or_m
(
isD
d
)
self
unsafeFreeze
$
MLGraph
gp
where
model'
=
case
model
of
GNP
->
IgraphErdosRenyiGnp
GNM
->
IgraphErdosRenyiGnm
This diff is collapsed.
Click to expand it.
src/IGraph/Internal/Constants.chs
View file @
f2bcfee7
...
...
@@ -25,3 +25,6 @@ import Foreign
{#enum igraph_pagerank_algo_t as PagerankAlgo {underscoreToCase}
deriving (Show, Read, Eq) #}
{#enum igraph_erdos_renyi_t as ErdosRenyi {underscoreToCase}
deriving (Show, Read, Eq) #}
This diff is collapsed.
Click to expand it.
src/IGraph/Internal/Graph.chs
View file @
f2bcfee7
...
...
@@ -49,4 +49,8 @@ igraphEdge g i = alloca $ \fr -> alloca $ \to -> do
{# fun igraph_add_edges as ^ { `IGraphPtr', `VectorPtr', id `Ptr ()' } -> `()' #}
-- generators
{#fun igraph_full as ^ { +, `Int', `Bool', `Bool' } -> `IGraphPtr' #}
{#fun igraph_erdos_renyi_game as ^ {+, `ErdosRenyi', `Int', `Double', `Bool', `Bool'} -> `IGraphPtr' #}
This diff is collapsed.
Click to expand it.
src/IGraph/Internal/Isomorphism.chs
0 → 100644
View file @
f2bcfee7
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Internal.Isomorphism where
import Foreign
import Foreign.C.Types
{#import IGraph.Internal.Graph #}
{#import IGraph.Internal.Data #}
#include "igraph/igraph.h"
{#fun igraph_get_subisomorphisms_vf2 as ^ { `IGraphPtr', `IGraphPtr',
id `Ptr ()', id `Ptr ()', id `Ptr ()', id `Ptr ()', `VectorPPtr',
id `FunPtr (Ptr IGraphPtr -> Ptr IGraphPtr -> CInt -> CInt -> Ptr () -> IO CInt)',
id `FunPtr (Ptr IGraphPtr -> Ptr IGraphPtr -> CInt -> CInt -> Ptr () -> IO CInt)',
id `Ptr ()'} -> `Int' #}
This diff is collapsed.
Click to expand it.
src/IGraph/Internal/Structure.chs
View file @
f2bcfee7
...
...
@@ -48,3 +48,14 @@ import Foreign.C.Types
, `Double'
, `VectorPtr'
, id `Ptr ()' } -> `Int' #}
{#fun igraph_personalized_pagerank as ^ { `IGraphPtr'
, `PagerankAlgo'
, `VectorPtr'
, id `Ptr CDouble'
, %`IGraphVsPtr'
, `Bool'
, `Double'
, `VectorPtr'
, `VectorPtr'
, id `Ptr ()' } -> `Int' #}
This diff is collapsed.
Click to expand it.
src/IGraph/Isomorphism.hs
0 → 100644
View file @
f2bcfee7
module
IGraph.Isomorphism
(
getSubisomorphisms
)
where
import
Foreign
import
Foreign.C.Types
import
System.IO.Unsafe
(
unsafePerformIO
)
import
IGraph
import
IGraph.Internal.Data
import
IGraph.Internal.Isomorphism
getSubisomorphisms
::
Graph
d
=>
LGraph
d
v1
e1
-- ^ graph to be searched in
->
LGraph
d
v2
e2
-- ^ smaller graph
->
[[
Int
]]
getSubisomorphisms
g1
g2
=
unsafePerformIO
$
do
vpptr
<-
igraphVectorPtrNew
0
igraphGetSubisomorphismsVf2
gptr1
gptr2
nullPtr
nullPtr
nullPtr
nullPtr
vpptr
nullFunPtr
nullFunPtr
nullPtr
(
map
.
map
)
truncate
<$>
vectorPPtrToList
vpptr
where
gptr1
=
_graph
g1
gptr2
=
_graph
g2
{-# INLINE getSubisomorphisms #-}
This diff is collapsed.
Click to expand it.
src/IGraph/Layout.hs
View file @
f2bcfee7
...
...
@@ -37,8 +37,8 @@ instance Default LayoutOpt where
data
LayoutMethod
=
KamadaKawai
getLayout
::
Graph
d
=>
LGraph
d
v
e
->
LayoutOpt
->
[(
Double
,
Double
)]
getLayout
gr
opt
=
unsafePerformIO
$
do
getLayout
::
Graph
d
=>
LGraph
d
v
e
->
LayoutOpt
->
IO
[(
Double
,
Double
)]
getLayout
gr
opt
=
do
mptr
<-
mat
case
_method
opt
of
...
...
This diff is collapsed.
Click to expand it.
src/IGraph/Motif.hs
0 → 100644
View file @
f2bcfee7
module
IGraph.Motif
(
triad
)
where
import
IGraph
-- | Every triple of vertices in a directed graph
-- 003: A, B, C, the empty graph.
-- 012: A->B, C, a graph with a single directed edge.
-- 102: A<->B, C, a graph with a mutual connection between two vertices.
-- 021D: A<-B->C, the binary out-tree.
-- 021U: A->B<-C, the binary in-tree.
-- 021C: A->B->C, the directed line.
-- 111D: A<->B<-C.
-- 111U: A<->B->C.
-- 030T: A->B<-C, A->C.
-- 030C: A<-B<-C, A->C.
-- 201: A<->B<->C.
-- 120D: A<-B->C, A<->C.
-- 120U: A->B<-C, A<->C.
-- 120C: A->B->C, A<->C.
-- 210: A->B<->C, A<->C.
-- 300: A<->B<->C, A<->C, the complete graph.
triad
::
[
LGraph
D
()
()
]
triad
=
map
make
xs
where
xs
=
[
[]
,
[(
0
,
1
)]
,
[(
0
,
1
),
(
1
,
0
)]
,
[(
1
,
0
),
(
1
,
2
)]
,
[(
0
,
1
),
(
2
,
1
)]
,
[(
0
,
1
),
(
1
,
2
)]
,
[(
0
,
1
),
(
1
,
0
),
(
2
,
1
)]
,
[(
0
,
1
),
(
1
,
0
),
(
1
,
2
)]
,
[(
0
,
1
),
(
2
,
1
),
(
0
,
2
)]
,
[(
1
,
0
),
(
2
,
1
),
(
0
,
2
)]
,
[(
0
,
1
),
(
1
,
0
),
(
0
,
2
),
(
2
,
0
)]
,
[(
1
,
0
),
(
1
,
2
),
(
0
,
2
),
(
2
,
0
)]
,
[(
0
,
1
),
(
2
,
1
),
(
0
,
2
),
(
2
,
0
)]
,
[(
0
,
1
),
(
1
,
2
),
(
0
,
2
),
(
2
,
0
)]
,
[(
0
,
1
),
(
1
,
2
),
(
2
,
1
),
(
0
,
2
),
(
2
,
0
)]
,
[(
0
,
1
),
(
1
,
2
),
(
1
,
2
),
(
2
,
1
),
(
0
,
2
),
(
2
,
0
)]
]
make
::
[(
Int
,
Int
)]
->
LGraph
D
()
()
make
xs
=
mkGraph
(
length
xs
,
Nothing
)
(
xs
,
Nothing
)
This diff is collapsed.
Click to expand it.
src/IGraph/Structure.hs
View file @
f2bcfee7
...
...
@@ -4,6 +4,7 @@ module IGraph.Structure
,
betweenness
,
eigenvectorCentrality
,
pagerank
,
personalizedPagerank
)
where
import
Control.Monad
...
...
@@ -95,3 +96,20 @@ pagerank gr ws d = unsafePerformIO $ alloca $ \p -> do
igraphPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
(
isDirected
gr
)
d
ws'
nullPtr
vectorPtrToList
vptr
personalizedPagerank
::
Graph
d
=>
LGraph
d
v
e
->
[
Double
]
-- ^ reset probability
->
Maybe
[
Double
]
->
Double
->
[
Double
]
personalizedPagerank
gr
reset
ws
d
=
unsafePerformIO
$
alloca
$
\
p
->
do
vptr
<-
igraphVectorNew
0
vsptr
<-
igraphVsAll
ws'
<-
case
ws
of
Just
w
->
listToVector
w
_
->
liftM
VectorPtr
$
newForeignPtr_
$
castPtr
nullPtr
reset'
<-
listToVector
reset
igraphPersonalizedPagerank
(
_graph
gr
)
IgraphPagerankAlgoPrpack
vptr
p
vsptr
(
isDirected
gr
)
d
reset'
ws'
nullPtr
vectorPtrToList
vptr
This diff is collapsed.
Click to expand it.
src/test.hs
View file @
f2bcfee7
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
import
Foreign
hiding
(
new
)
import
Control.Monad
import
Data.Serialize
import
qualified
Data.ByteString.Char8
as
B
import
qualified
Data.HashMap.Strict
as
M
import
IGraph
import
IGraph.Read
import
Text.XML.HXT.Core
import
IGraph.Export.GEXF
import
IGraph.Generators
import
IGraph.Layout
import
System.Environment
import
Data.Default
main
=
do
-- [fl] <- getArgs
-- g <- readAdjMatrix fl :: IO (LGraph U B.ByteString Double)
let
t
=
genXMLTree
undefined
::
IOStateArrow
s
XmlTree
XmlTree
[
x
]
<-
runX
$
root
[]
[
t
]
>>>
writeDocumentToString
[
withXmlPi
yes
,
withIndent
yes
]
putStrLn
x
gr
<-
erdosRenyiGame
GNM
100
50
U
False
coord
<-
getLayout
gr
def
This diff is collapsed.
Click to expand it.
stack.yaml
View file @
f2bcfee7
...
...
@@ -2,7 +2,7 @@ flags: {}
packages
:
-
'
.'
extra-deps
:
[]
resolver
:
lts-5.
4
resolver
:
lts-5.
5
extra-lib-dirs
:
-
"
/home/kai/opt/lib"
This diff is collapsed.
Click to expand it.
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