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
1bc3746a
Commit
1bc3746a
authored
Sep 01, 2020
by
Jean-Baptiste Mazon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add diameter
parent
34553acc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
0 deletions
+43
-0
Structure.chs
src/IGraph/Algorithms/Structure.chs
+29
-0
Internal.chs
src/IGraph/Internal.chs
+5
-0
Algorithms.hs
tests/Test/Algorithms.hs
+9
-0
No files found.
src/IGraph/Algorithms/Structure.chs
View file @
1bc3746a
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
module IGraph.Algorithms.Structure
module IGraph.Algorithms.Structure
( -- * Shortest Path Related Functions
( -- * Shortest Path Related Functions
shortestPath
shortestPath
, diameter
, inducedSubgraph
, inducedSubgraph
, isConnected
, isConnected
, isStronglyConnected
, isStronglyConnected
...
@@ -64,6 +65,29 @@ shortestPath gr s t getEdgeW = unsafePerformIO $ allocaVector $ \path -> do
...
@@ -64,6 +65,29 @@ shortestPath gr s t getEdgeW = unsafePerformIO $ allocaVector $ \path -> do
, `Neimode'
, `Neimode'
} -> `CInt' void- #}
} -> `CInt' void- #}
-- | Calculates the diameter of a graph (longest geodesic).
diameter :: Graph d v e
-> EdgeType -- ^ whether to consider directed paths
-> Bool -- ^ if unconnected,
-- return largest component diameter (True)
-- or number of vertices (False)
-> (Int,[Node])
diameter graph directed unconn = unsafePerformIO $
alloca $ \pres ->
allocaVector $ \path -> do
igraphDiameter (_graph graph) pres nullPtr nullPtr path directed unconn
liftM2 (,) (peekIntConv pres) (toNodes path)
{-# INLINE igraphDiameter #-}
{#fun igraph_diameter as ^
{ `IGraph'
, castPtr `Ptr CInt'
, castPtr `Ptr CInt'
, castPtr `Ptr CInt'
, castPtr `Ptr Vector'
, dirToBool `EdgeType'
, `Bool'
} -> `CInt' void- #}
-- | Creates a subgraph induced by the specified vertices. This function collects
-- | Creates a subgraph induced by the specified vertices. This function collects
-- the specified vertices and all edges between them to a new graph.
-- the specified vertices and all edges between them to a new graph.
inducedSubgraph :: (Ord v, Serialize v)
inducedSubgraph :: (Ord v, Serialize v)
...
@@ -144,3 +168,8 @@ topSortUnsafe gr = unsafePerformIO $ allocaVectorN n $ \res -> do
...
@@ -144,3 +168,8 @@ topSortUnsafe gr = unsafePerformIO $ allocaVectorN n $ \res -> do
, castPtr `Ptr Vector'
, castPtr `Ptr Vector'
, `Neimode'
, `Neimode'
} -> `CInt' void- #}
} -> `CInt' void- #}
-- Marshaller for those "treat edges as directed" booleans.
dirToBool :: Num n => EdgeType -> n
dirToBool D = cFromBool True
dirToBool U = cFromBool False
src/IGraph/Internal.chs
View file @
1bc3746a
...
@@ -8,6 +8,7 @@ module IGraph.Internal
...
@@ -8,6 +8,7 @@ module IGraph.Internal
, withList
, withList
, withListMaybe
, withListMaybe
, toList
, toList
, toNodes
, igraphVectorNull
, igraphVectorNull
, igraphVectorFill
, igraphVectorFill
, igraphVectorE
, igraphVectorE
...
@@ -193,6 +194,10 @@ toList vec = do
...
@@ -193,6 +194,10 @@ toList vec = do
map realToFrac <$> peekArray n ptr
map realToFrac <$> peekArray n ptr
{-# INLINE toList #-}
{-# INLINE toList #-}
toNodes :: Ptr Vector -> IO [Node]
toNodes = fmap (map truncate) . toList
{-# INLINE toNodes #-}
{#fun igraph_vector_copy_to as ^ { castPtr `Ptr Vector', id `Ptr CDouble' } -> `()' #}
{#fun igraph_vector_copy_to as ^ { castPtr `Ptr Vector', id `Ptr CDouble' } -> `()' #}
-- Initializing elements
-- Initializing elements
...
...
tests/Test/Algorithms.hs
View file @
1bc3746a
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeApplications #-}
module
Test.Algorithms
module
Test.Algorithms
(
tests
(
tests
)
where
)
where
...
@@ -20,6 +21,7 @@ tests = testGroup "Algorithms"
...
@@ -20,6 +21,7 @@ tests = testGroup "Algorithms"
[
graphIsomorphism
[
graphIsomorphism
,
motifTest
,
motifTest
,
cliqueTest
,
cliqueTest
,
diameterTest
,
subGraphs
,
subGraphs
,
decomposeTest
,
decomposeTest
,
pagerankTest
,
pagerankTest
...
@@ -55,6 +57,13 @@ cliqueTest = testGroup "Clique"
...
@@ -55,6 +57,13 @@ cliqueTest = testGroup "Clique"
[
2
,
3
,
4
],
[
2
,
4
,
5
]
]
[
2
,
3
,
4
],
[
2
,
4
,
5
]
]
c4
=
[[
1
,
2
,
3
,
4
],
[
1
,
2
,
4
,
5
]]
c4
=
[[
1
,
2
,
3
,
4
],
[
1
,
2
,
4
,
5
]]
diameterTest
::
TestTree
diameterTest
=
testGroup
"Diameters"
[
testCase
"clique"
$
fst
(
diameter
(
full
@
'U
10
False
)
U
True
)
@?=
1
,
testCase
"star"
$
fst
(
diameter
(
star
10
)
D
False
)
@?=
2
,
testCase
"ring"
$
fst
(
diameter
(
ring
10
)
U
False
)
@?=
5
]
subGraphs
::
TestTree
subGraphs
::
TestTree
subGraphs
=
testGroup
"generate induced subgraphs"
subGraphs
=
testGroup
"generate induced subgraphs"
[
testCase
""
$
test
case1
]
[
testCase
""
$
test
case1
]
...
...
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