]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Viz/Graph/IGraph.hs
[DEPS] stack upgrade
[gargantext.git] / src / Gargantext / Core / Viz / Graph / IGraph.hs
1 {-| Module : Gargantext.Core.Viz.Graph.IGraph
2 Description : IGraph main functions used in Garg
3 Copyright : (c) CNRS, 2017-Present
4 License : AGPL + CECILL v3
5 Maintainer : team@gargantext.org
6 Stability : experimental
7 Portability : POSIX
8
9 Main IGraph funs/types to ease portability with FGL.
10
11 Reference:
12 * Gábor Csárdi, Tamás Nepusz: The igraph software package for complex network research. InterJournal Complex Systems, 1695, 2006.
13
14 -}
15
16
17 module Gargantext.Core.Viz.Graph.IGraph where
18
19 import Data.Serialize (Serialize)
20 import Data.Singletons (SingI)
21 import Gargantext.Prelude
22 import IGraph hiding (mkGraph, neighbors, edges, nodes, Node, Graph)
23 import IGraph.Algorithms.Clique as IAC
24 import qualified IGraph as IG
25 import qualified Data.List as List
26
27 ------------------------------------------------------------------
28 -- | Main Types
29 type Graph_Undirected = IG.Graph 'U () ()
30 type Graph_Directed = IG.Graph 'D () ()
31
32 type Node = IG.Node
33 type Graph = IG.Graph
34
35 ------------------------------------------------------------------
36 -- | Main Functions
37
38 mkGraph :: (SingI d, Ord v,
39 Serialize v, Serialize e) =>
40 [v] -> [LEdge e] -> IG.Graph d v e
41 mkGraph = IG.mkGraph
42
43 neighbors :: IG.Graph d v e -> IG.Node -> [Node]
44 neighbors = IG.neighbors
45
46 edges :: IG.Graph d v e -> [Edge]
47 edges = IG.edges
48
49 nodes :: IG.Graph d v e -> [Node]
50 nodes = IG.nodes
51 ------------------------------------------------------------------
52
53 -- | Tools
54 maximalCliques :: IG.Graph d v e -> [[Int]]
55 maximalCliques g = IAC.maximalCliques g (min',max')
56 where
57 min' = 0
58 max' = 0
59
60 ------------------------------------------------------------------
61 -- | Main sugared functions
62 mkGraphUfromEdges :: [(Int, Int)] -> Graph_Undirected
63 mkGraphUfromEdges es = mkGraph (List.replicate n ()) $ zip es $ repeat ()
64 where
65 (a,b) = List.unzip es
66 n = List.length (List.nub $ a <> b)
67
68 mkGraphDfromEdges :: [(Int, Int)] -> Graph_Directed
69 mkGraphDfromEdges = undefined
70
71