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
de2ab7cc
Commit
de2ab7cc
authored
May 11, 2018
by
Kai Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add shortest path
parent
5a0af3fd
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
156 additions
and
138 deletions
+156
-138
haskell-igraph.cabal
haskell-igraph.cabal
+12
-13
IGraph.hs
src/IGraph.hs
+5
-1
Algorithms.hs
src/IGraph/Algorithms.hs
+17
-0
Clique.chs
src/IGraph/Algorithms/Clique.chs
+1
-1
Community.chs
src/IGraph/Algorithms/Community.chs
+1
-1
Generators.chs
src/IGraph/Algorithms/Generators.chs
+1
-1
Isomorphism.chs
src/IGraph/Algorithms/Isomorphism.chs
+1
-1
Layout.chs
src/IGraph/Algorithms/Layout.chs
+1
-1
Motif.chs
src/IGraph/Algorithms/Motif.chs
+1
-1
Structure.chs
src/IGraph/Algorithms/Structure.chs
+32
-3
Internal.chs
src/IGraph/Internal.chs
+1
-1
Types.hs
src/IGraph/Types.hs
+1
-1
Algorithms.hs
tests/Test/Algorithms.hs
+76
-0
Attributes.hs
tests/Test/Attributes.hs
+0
-7
Basic.hs
tests/Test/Basic.hs
+2
-4
Isomorphism.hs
tests/Test/Isomorphism.hs
+0
-26
Motif.hs
tests/Test/Motif.hs
+0
-21
Structure.hs
tests/Test/Structure.hs
+0
-45
test.hs
tests/test.hs
+4
-10
No files found.
haskell-igraph.cabal
View file @
de2ab7cc
name: haskell-igraph
version: 0.
6.0
version: 0.
7.0-dev
synopsis: Haskell interface of the igraph library.
description: igraph<"http://igraph.org/c/"> is a library for creating
and manipulating large graphs. This package provides the Haskell
...
...
@@ -29,17 +29,18 @@ library
IGraph.Internal.Constants
IGraph.Internal
IGraph
IGraph.Types
IGraph.Mutable
IGraph.Clique
IGraph.Structure
IGraph.Isomorphism
IGraph.Community
IGraph.Types
IGraph.Read
IGraph.Motif
IGraph.Layout
IGraph.Generators
IGraph.Exporter.GEXF
IGraph.Algorithms
IGraph.Algorithms.Structure
IGraph.Algorithms.Community
IGraph.Algorithms.Clique
IGraph.Algorithms.Layout
IGraph.Algorithms.Motif
IGraph.Algorithms.Generators
IGraph.Algorithms.Isomorphism
other-modules:
IGraph.Internal.C2HS
...
...
@@ -79,14 +80,12 @@ library
test-suite tests
type: exitcode-stdio-1.0
hs-source-dirs: tests
ghc-options: -Wall
main-is: test.hs
other-modules:
Test.Basic
Test.Attributes
Test.Structure
Test.Isomorphism
Test.Motif
Test.Clique
Test.Algorithms
Test.Utils
default-language: Haskell2010
...
...
src/IGraph.hs
View file @
de2ab7cc
...
...
@@ -6,6 +6,10 @@
module
IGraph
(
Graph
(
..
)
,
EdgeType
(
..
)
,
Node
,
LNode
,
Edge
,
LEdge
,
isDirected
,
nNodes
,
nodeLab
...
...
@@ -115,7 +119,7 @@ nEdges :: Graph d v e -> Int
nEdges
=
unsafePerformIO
.
igraphEcount
.
_graph
{-# INLINE nEdges #-}
-- | Return all edges.
-- | Return all edges.
edges
::
Graph
d
v
e
->
[
Edge
]
edges
gr
=
map
(
getEdgeByEid
gr
)
[
0
..
nEdges
gr
-
1
]
{-# INLINE edges #-}
...
...
src/IGraph/Algorithms.hs
0 → 100644
View file @
de2ab7cc
module
IGraph.Algorithms
(
module
IGraph
.
Algorithms
.
Structure
,
module
IGraph
.
Algorithms
.
Community
,
module
IGraph
.
Algorithms
.
Clique
,
module
IGraph
.
Algorithms
.
Layout
,
module
IGraph
.
Algorithms
.
Motif
,
module
IGraph
.
Algorithms
.
Generators
,
module
IGraph
.
Algorithms
.
Isomorphism
)
where
import
IGraph.Algorithms.Structure
import
IGraph.Algorithms.Community
import
IGraph.Algorithms.Clique
import
IGraph.Algorithms.Layout
import
IGraph.Algorithms.Motif
import
IGraph.Algorithms.Generators
import
IGraph.Algorithms.Isomorphism
src/IGraph/Clique.chs
→
src/IGraph/
Algorithms/
Clique.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Clique
module IGraph.
Algorithms.
Clique
( cliques
, largestCliques
, maximalCliques
...
...
src/IGraph/Community.chs
→
src/IGraph/
Algorithms/
Community.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DataKinds #-}
module IGraph.Community
module IGraph.
Algorithms.
Community
( modularity
, findCommunity
, CommunityMethod(..)
...
...
src/IGraph/Generators.chs
→
src/IGraph/
Algorithms/
Generators.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
module IGraph.Generators
module IGraph.
Algorithms.
Generators
( full
, star
, ErdosRenyiModel(..)
...
...
src/IGraph/Isomorphism.chs
→
src/IGraph/
Algorithms/
Isomorphism.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE ScopedTypeVariables #-}
module IGraph.Isomorphism
module IGraph.
Algorithms.
Isomorphism
( getSubisomorphisms
, isomorphic
, isoclassCreate
...
...
src/IGraph/Layout.chs
→
src/IGraph/
Algorithms/
Layout.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Layout
module IGraph.
Algorithms.
Layout
( getLayout
, LayoutMethod(..)
, defaultKamadaKawai
...
...
src/IGraph/Motif.chs
→
src/IGraph/
Algorithms/
Motif.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DataKinds #-}
module IGraph.Motif
module IGraph.
Algorithms.
Motif
( triad
, triadCensus
) where
...
...
src/IGraph/Structure.chs
→
src/IGraph/
Algorithms/
Structure.chs
View file @
de2ab7cc
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Structure
( inducedSubgraph
module IGraph.Algorithms.Structure
( -- * Shortest Path Related Functions
getShortestPath
, inducedSubgraph
, closeness
, betweenness
, eigenvectorCentrality
...
...
@@ -24,7 +26,34 @@ import IGraph.Mutable (MGraph(..))
{#import IGraph.Internal #}
{#import IGraph.Internal.Constants #}
#include "igraph/igraph.h"
#include "haskell_igraph.h"
{#fun igraph_shortest_paths as ^
{ `IGraph'
, castPtr `Ptr Matrix'
, castPtr %`Ptr VertexSelector'
, castPtr %`Ptr VertexSelector'
, `Neimode'
} -> `CInt' void- #}
-- Calculates and returns a single unweighted shortest path from a given vertex
-- to another one. If there are more than one shortest paths between the two
-- vertices, then an arbitrary one is returned.
getShortestPath :: Graph d v e
-> Node -- ^ The id of the source vertex.
-> Node -- ^ The id of the target vertex.
-> [Node]
getShortestPath gr s t = unsafePerformIO $ allocaVector $ \path -> do
igraphGetShortestPath (_graph gr) path nullPtr s t IgraphOut
map truncate <$> toList path
{#fun igraph_get_shortest_path as ^
{ `IGraph'
, castPtr `Ptr Vector'
, castPtr `Ptr Vector'
, `Int'
, `Int'
, `Neimode'
} -> `CInt' void- #}
inducedSubgraph :: (Hashable v, Eq v, Serialize v)
=> Graph d v e
...
...
src/IGraph/Internal.chs
View file @
de2ab7cc
...
...
@@ -172,7 +172,7 @@ toList vec = do
n <- igraphVectorSize vec
allocaArray n $ \ptr -> do
igraphVectorCopyTo vec ptr
liftM (map realToFrac) $
peekArray n ptr
map realToFrac <$>
peekArray n ptr
{-# INLINE toList #-}
{#fun igraph_vector_copy_to as ^ { castPtr `Ptr Vector', id `Ptr CDouble' } -> `()' #}
...
...
src/IGraph/Types.hs
View file @
de2ab7cc
...
...
@@ -24,7 +24,7 @@ import GHC.Generics (Generic)
$
(
singletons
[
d
|
data EdgeType = D
| U
deriving (
Show, Read,
Eq, Generic)
deriving (Eq, Generic)
|]
)
instance
Serialize
EdgeType
...
...
tests/Test/
Clique
.hs
→
tests/Test/
Algorithms
.hs
View file @
de2ab7cc
{-# LANGUAGE DataKinds #-}
module
Test.
Clique
module
Test.
Algorithms
(
tests
)
where
import
Control.Arrow
import
Control.Monad.ST
import
Data.List
import
System.IO.Unsafe
import
qualified
Data.Matrix.Unboxed
as
M
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Utils
import
IGraph
import
IGraph.Clique
import
IGraph.Generators
import
IGraph.Algorithms
import
IGraph.Mutable
tests
::
TestTree
tests
=
testGroup
"Clique"
tests
=
testGroup
"Algorithms"
[
graphIsomorphism
,
motifTest
,
cliqueTest
,
subGraphs
,
pagerankTest
]
graphIsomorphism
::
TestTree
graphIsomorphism
=
testCase
"Graph isomorphism"
$
assertBool
""
$
and
(
zipWith
isomorphic
triad
triad
)
&&
(
not
.
or
)
(
zipWith
isomorphic
triad
$
reverse
triad
)
motifTest
::
TestTree
motifTest
=
testGroup
"Network motif"
[
testCase
"triad Census"
$
M
.
toLists
(
M
.
ident
16
::
M
.
Matrix
Int
)
@=?
map
triadCensus
triad
]
cliqueTest
::
TestTree
cliqueTest
=
testGroup
"Clique"
[
testCase
"case 1"
$
sort
(
map
sort
$
cliques
gr
(
4
,
-
1
))
@=?
c4
,
testCase
"case 2"
$
sort
(
map
sort
$
cliques
gr
(
2
,
2
))
@=?
c2
,
testCase
"case 3"
$
sort
(
map
sort
$
largestCliques
gr
)
@=?
c4
...
...
@@ -34,3 +52,25 @@ tests = testGroup "Clique"
c3
=
[
[
0
,
3
,
4
],
[
0
,
4
,
5
],
[
1
,
2
,
3
],
[
1
,
2
,
4
],
[
1
,
2
,
5
],
[
1
,
3
,
4
],
[
1
,
4
,
5
],
[
2
,
3
,
4
],
[
2
,
4
,
5
]
]
c4
=
[[
1
,
2
,
3
,
4
],
[
1
,
2
,
4
,
5
]]
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
$
zip
ori
$
repeat
()
::
Graph
'D
String
()
ns'
=
map
(
head
.
getNodes
gr
)
ns
gr'
=
inducedSubgraph
gr
ns'
result
=
map
(
nodeLab
gr'
***
nodeLab
gr'
)
$
edges
gr'
pagerankTest
::
TestTree
pagerankTest
=
testGroup
"PageRank"
[
testCase
"case 1"
$
ranks
@=?
ranks'
]
where
gr
=
star
11
ranks
=
[
0.47
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
]
ranks'
=
map
((
/
100
)
.
fromIntegral
.
round
.
(
*
100
))
$
pagerank
gr
Nothing
Nothing
0.85
tests/Test/Attributes.hs
View file @
de2ab7cc
...
...
@@ -3,14 +3,8 @@ module Test.Attributes
(
tests
)
where
import
Conduit
import
Control.Monad
import
Control.Monad.ST
import
Data.List
import
Data.List.Ordered
(
nubSort
)
import
Data.Maybe
import
Data.Serialize
import
Foreign
import
System.IO.Unsafe
import
Test.Tasty
import
Test.Tasty.HUnit
...
...
@@ -20,7 +14,6 @@ import IGraph
import
IGraph.Exporter.GEXF
import
IGraph.Internal
import
IGraph.Mutable
import
IGraph.Structure
tests
::
TestTree
tests
=
testGroup
"Attribute tests"
...
...
tests/Test/Basic.hs
View file @
de2ab7cc
...
...
@@ -3,19 +3,17 @@ module Test.Basic
(
tests
)
where
import
Conduit
import
Control.Monad.ST
import
Data.List
import
Data.List.Ordered
(
nubSort
)
import
Data.Maybe
import
System.IO.Unsafe
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Utils
import
Conduit
import
IGraph
import
qualified
IGraph.Mutable
as
GM
import
IGraph.Structure
import
qualified
IGraph.Mutable
as
GM
tests
::
TestTree
tests
=
testGroup
"Basic tests"
...
...
tests/Test/Isomorphism.hs
deleted
100644 → 0
View file @
5a0af3fd
module
Test.Isomorphism
(
tests
)
where
import
Control.Arrow
import
Control.Monad.ST
import
Data.List
import
qualified
Data.Matrix.Unboxed
as
M
import
System.IO.Unsafe
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Utils
import
IGraph
import
IGraph
import
IGraph.Motif
import
IGraph.Isomorphism
tests
::
TestTree
tests
=
testGroup
"Isomorphism"
[
graphIsomorphism
]
graphIsomorphism
::
TestTree
graphIsomorphism
=
testCase
"Graph isomorphism"
$
assertBool
""
$
and
(
zipWith
isomorphic
triad
triad
)
&&
(
not
.
or
)
(
zipWith
isomorphic
triad
$
reverse
triad
)
tests/Test/Motif.hs
deleted
100644 → 0
View file @
5a0af3fd
module
Test.Motif
(
tests
)
where
import
Control.Arrow
import
Control.Monad.ST
import
Data.List
import
qualified
Data.Matrix.Unboxed
as
M
import
System.IO.Unsafe
import
Test.Tasty
import
Test.Tasty.HUnit
import
Test.Utils
import
IGraph
import
IGraph
import
IGraph.Motif
tests
::
TestTree
tests
=
testGroup
"Network motif"
[
testCase
"triad Census"
$
M
.
toLists
(
M
.
ident
16
::
M
.
Matrix
Int
)
@=?
map
triadCensus
triad
]
tests/Test/Structure.hs
deleted
100644 → 0
View file @
5a0af3fd
{-# LANGUAGE DataKinds #-}
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
import
IGraph.Generators
tests
::
TestTree
tests
=
testGroup
"Structure property tests"
[
subGraphs
,
pagerankTest
]
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
$
zip
ori
$
repeat
()
::
Graph
'D
String
()
ns'
=
map
(
head
.
getNodes
gr
)
ns
gr'
=
inducedSubgraph
gr
ns'
result
=
map
(
nodeLab
gr'
***
nodeLab
gr'
)
$
edges
gr'
pagerankTest
::
TestTree
pagerankTest
=
testGroup
"PageRank"
[
testCase
"case 1"
$
ranks
@=?
ranks'
]
where
gr
=
star
11
ranks
=
[
0.47
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
,
0.05
]
ranks'
=
map
((
/
100
)
.
fromIntegral
.
round
.
(
*
100
))
$
pagerank
gr
Nothing
Nothing
0.85
tests/test.hs
View file @
de2ab7cc
import
qualified
Test.Attributes
as
Attributes
import
qualified
Test.Basic
as
Basic
import
qualified
Test.Clique
as
Clique
import
qualified
Test.Isomorphism
as
Isomorphism
import
qualified
Test.Motif
as
Motif
import
qualified
Test.Structure
as
Structure
import
qualified
Test.Algorithms
as
Algorithms
import
qualified
Test.Attributes
as
Attributes
import
qualified
Test.Basic
as
Basic
import
Test.Tasty
main
::
IO
()
main
=
defaultMain
$
testGroup
"Haskell-igraph Tests"
[
Basic
.
tests
,
Structure
.
tests
,
Motif
.
tests
,
Isomorphism
.
tests
,
Algorithms
.
tests
,
Attributes
.
tests
,
Clique
.
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