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
287c8e77
Commit
287c8e77
authored
Nov 26, 2015
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add inducedSubgraph
parent
5926cead
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
75 additions
and
3 deletions
+75
-3
Structure.chs.c
cbits/Structure.chs.c
+7
-0
IGraph.hs
src/IGraph.hs
+4
-0
Constants.chs
src/IGraph/Internal/Constants.chs
+3
-0
Structure.chs
src/IGraph/Internal/Structure.chs
+6
-1
Structure.hs
src/IGraph/Structure.hs
+19
-2
Basic.hs
tests/Test/Basic.hs
+1
-0
Structure.hs
tests/Test/Structure.hs
+33
-0
test.hs
tests/test.hs
+2
-0
No files found.
cbits/Structure.chs.c
View file @
287c8e77
#include "IGraph/Internal/Structure.chs.h"
#include "IGraph/Internal/Structure.chs.h"
int
__c2hs_wrapped__igraph_induced_subgraph
(
const
igraph_t
*
graph
,
igraph_t
*
res
,
const
igraph_vs_t
*
vids
,
igraph_subgraph_implementation_t
impl
)
{
return
igraph_induced_subgraph
(
graph
,
res
,
*
vids
,
impl
);
}
int
__c2hs_wrapped__igraph_closeness
(
const
igraph_t
*
graph
,
int
__c2hs_wrapped__igraph_closeness
(
const
igraph_t
*
graph
,
igraph_vector_t
*
res
,
igraph_vector_t
*
res
,
const
igraph_vs_t
*
vids
,
const
igraph_vs_t
*
vids
,
...
...
src/IGraph.hs
View file @
287c8e77
...
@@ -78,6 +78,10 @@ class MGraph d => Graph d where
...
@@ -78,6 +78,10 @@ class MGraph d => Graph d where
else
Nothing
else
Nothing
{-# INLINE nodeLabMaybe #-}
{-# INLINE nodeLabMaybe #-}
getNodes
::
(
Hashable
v
,
Eq
v
)
=>
LGraph
d
v
e
->
v
->
[
Node
]
getNodes
gr
x
=
M
.
lookupDefault
[]
x
$
_labelToNode
gr
{-# INLINE getNodes #-}
edgeLab
::
Read
e
=>
LGraph
d
v
e
->
Edge
->
e
edgeLab
::
Read
e
=>
LGraph
d
v
e
->
Edge
->
e
edgeLab
(
LGraph
g
_
)
(
fr
,
to
)
=
read
$
igraphCattributeEAS
g
edgeAttr
$
edgeLab
(
LGraph
g
_
)
(
fr
,
to
)
=
read
$
igraphCattributeEAS
g
edgeAttr
$
igraphGetEid
g
fr
to
True
True
igraphGetEid
g
fr
to
True
True
...
...
src/IGraph/Internal/Constants.chs
View file @
287c8e77
...
@@ -14,3 +14,6 @@ import Foreign
...
@@ -14,3 +14,6 @@ import Foreign
{#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_spinglass_implementation_t as SpinglassImplementation {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_attribute_elemtype_t as AttributeElemtype {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_attribute_elemtype_t as AttributeElemtype {underscoreToCase} deriving (Show, Eq) #}
{#enum igraph_subgraph_implementation_t as SubgraphImplementation {underscoreToCase}
deriving (Show, Read, Eq) #}
src/IGraph/Internal/Structure.chs
View file @
287c8e77
...
@@ -12,6 +12,11 @@ import Foreign.C.Types
...
@@ -12,6 +12,11 @@ import Foreign.C.Types
#include "igraph/igraph.h"
#include "igraph/igraph.h"
{#fun igraph_induced_subgraph as ^ { `IGraphPtr'
, id `Ptr (IGraphPtr)'
, %`IGraphVsPtr'
, `SubgraphImplementation' } -> `Int' #}
{#fun igraph_closeness as ^ { `IGraphPtr'
{#fun igraph_closeness as ^ { `IGraphPtr'
, `VectorPtr'
, `VectorPtr'
, %`IGraphVsPtr'
, %`IGraphVsPtr'
...
@@ -22,7 +27,7 @@ import Foreign.C.Types
...
@@ -22,7 +27,7 @@ import Foreign.C.Types
{#fun igraph_betweenness as ^ { `IGraphPtr'
{#fun igraph_betweenness as ^ { `IGraphPtr'
, `VectorPtr'
, `VectorPtr'
, %`IGraphVsPtr'
, %`IGraphVsPtr'
, `Bool'
, `Bool'
, `VectorPtr'
, `VectorPtr'
, `Bool' } -> `Int' #}
, `Bool' } -> `Int' #}
...
...
src/IGraph/Structure.hs
View file @
287c8e77
module
IGraph.Structure
module
IGraph.Structure
(
closeness
(
inducedSubgraph
,
closeness
,
betweenness
,
betweenness
,
eigenvectorCentrality
,
eigenvectorCentrality
)
where
)
where
...
@@ -8,14 +9,30 @@ import Control.Monad
...
@@ -8,14 +9,30 @@ import Control.Monad
import
Foreign
import
Foreign
import
Foreign.C.Types
import
Foreign.C.Types
import
System.IO.Unsafe
(
unsafePerformIO
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
qualified
Data.HashMap.Strict
as
M
import
Data.Hashable
(
Hashable
)
import
IGraph
import
IGraph
import
IGraph.Mutable
(
U
)
import
IGraph.Mutable
import
IGraph.Internal.Graph
import
IGraph.Internal.Data
import
IGraph.Internal.Data
import
IGraph.Internal.Selector
import
IGraph.Internal.Selector
import
IGraph.Internal.Structure
import
IGraph.Internal.Structure
import
IGraph.Internal.Arpack
import
IGraph.Internal.Arpack
import
IGraph.Internal.Constants
import
IGraph.Internal.Constants
import
IGraph.Internal.Attribute
inducedSubgraph
::
(
Hashable
v
,
Eq
v
,
Read
v
)
=>
LGraph
d
v
e
->
[
Int
]
->
LGraph
d
v
e
inducedSubgraph
gr
vs
=
unsafePerformIO
$
do
vs'
<-
listToVector
$
map
fromIntegral
vs
vsptr
<-
igraphVsVector
vs'
mallocForeignPtrBytes
160
>>=
\
gptr
->
withForeignPtr
gptr
$
\
p
->
do
igraphInducedSubgraph
(
_graph
gr
)
p
vsptr
IgraphSubgraphCreateFromScratch
let
g'
=
IGraphPtr
gptr
labToId
=
M
.
fromListWith
(
++
)
$
zip
labels
$
map
return
[
0
..
nV
-
1
]
nV
=
igraphVcount
g'
labels
=
map
(
read
.
igraphCattributeVAS
g'
vertexAttr
)
[
0
..
nV
-
1
]
return
$
LGraph
g'
labToId
-- | closeness centrality
-- | closeness centrality
closeness
::
[
Int
]
-- ^ vertices
closeness
::
[
Int
]
-- ^ vertices
...
...
tests/Test/Basic.hs
View file @
287c8e77
...
@@ -11,6 +11,7 @@ import Data.List
...
@@ -11,6 +11,7 @@ import Data.List
import
IGraph
import
IGraph
import
IGraph.Mutable
import
IGraph.Mutable
import
IGraph.Structure
tests
::
TestTree
tests
::
TestTree
tests
=
testGroup
"Basic tests"
tests
=
testGroup
"Basic tests"
...
...
tests/Test/Structure.hs
0 → 100644
View file @
287c8e77
module
Test.Structure
(
tests
)
where
import
Control.Arrow
import
Control.Monad.ST
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Utils
import
System.IO.Unsafe
import
Data.List
import
IGraph
import
IGraph.Mutable
import
IGraph.Structure
tests
::
TestTree
tests
=
testGroup
"Structure property tests"
[
subGraphs
]
subGraphs
::
TestTree
subGraphs
=
testGroup
"generate induced subgraphs"
[
testCase
""
$
test
case1
]
where
case1
=
(
[(
"a"
,
"b"
),
(
"b"
,
"c"
),
(
"c"
,
"a"
),
(
"a"
,
"c"
)]
,
[
"a"
,
"c"
],
[(
"a"
,
"c"
),
(
"c"
,
"a"
)]
)
test
(
ori
,
ns
,
expect
)
=
sort
expect
@=?
sort
result
where
gr
=
fromLabeledEdges
ori
::
LGraph
D
String
()
ns'
=
map
(
head
.
getNodes
gr
)
ns
gr'
=
inducedSubgraph
gr
ns'
result
=
map
(
nodeLab
gr'
***
nodeLab
gr'
)
$
edges
gr'
tests/test.hs
View file @
287c8e77
import
qualified
Test.Basic
as
Basic
import
qualified
Test.Basic
as
Basic
import
qualified
Test.Structure
as
Structure
import
Test.Tasty
import
Test.Tasty
main
::
IO
()
main
::
IO
()
main
=
defaultMain
$
testGroup
"Haskell-igraph Tests"
main
=
defaultMain
$
testGroup
"Haskell-igraph Tests"
[
Basic
.
tests
[
Basic
.
tests
,
Structure
.
tests
]
]
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