2 Module : Gargantext.Core.Viz.Graph.Tools.IGraph
3 Description : Tools to build Graph
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 * Gábor Csárdi, Tamás Nepusz: The igraph software package for complex network research. InterJournal Complex Systems, 1695, 2006.
16 module Gargantext.Core.Viz.Graph.Tools.IGraph
20 import Data.Singletons (SingI)
21 import IGraph hiding (mkGraph, neighbors, edges, nodes, Node, Graph)
23 import qualified Data.List as List
24 import qualified IGraph as IG
25 import qualified IGraph.Algorithms.Clique as IG
26 import qualified IGraph.Algorithms.Community as IG
27 import qualified IGraph.Random as IG
29 ------------------------------------------------------------------
31 type Graph_Undirected = IG.Graph 'U () ()
32 type Graph_Directed = IG.Graph 'D () ()
37 ------------------------------------------------------------------
38 -- | Main Graph management Functions
39 neighbors :: IG.Graph d v e -> IG.Node -> [IG.Node]
40 neighbors = IG.neighbors
42 edges :: IG.Graph d v e -> [Edge]
45 nodes :: IG.Graph d v e -> [IG.Node]
48 ------------------------------------------------------------------
50 maximalCliques :: IG.Graph d v e -> [[Int]]
51 maximalCliques g = IG.maximalCliques g (min',max')
56 ------------------------------------------------------------------
59 -- | Tools to analyze graphs
60 partitions_spinglass :: (Serialize v, Serialize e)
61 => Seed -> IG.Graph 'U v e -> IO [[Int]]
62 partitions_spinglass s g = do
63 gen <- IG.withSeed s pure
64 pure $ IG.findCommunity g Nothing Nothing IG.spinglass gen
66 ------------------------------------------------------------------
68 mkGraph :: (SingI d, Ord v,
69 Serialize v, Serialize e) =>
70 [v] -> [LEdge e] -> IG.Graph d v e
74 ------------------------------------------------------------------
75 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
76 mkGraphUfromEdges es = mkGraph (List.replicate n ()) $ zip es $ repeat ()
79 n = List.length (List.nub $ a <> b)
81 mkGraphDfromEdges :: [(Int, Int)] -> Graph_Directed
82 mkGraphDfromEdges = undefined