1 {-# LANGUAGE NoImplicitPrelude #-}
3 module Gargantext.Viz.Graph.MaxClique where
5 import Gargantext.Prelude
6 import Data.List (sortOn, nub)
8 import Data.Graph.Inductive hiding (Graph, neighbors, subgraph)
9 import qualified Data.Graph.Inductive as DGI
10 import Gargantext.Viz.Graph.FGL (Graph_Undirected, degree, neighbors, mkGraphUfromEdges)
11 import qualified Data.Set as Set
13 type Graph = Graph_Undirected
16 subgraph g ns = DGI.subgraph ns g
18 subGraphOn :: Graph -> Node -> Graph
19 subGraphOn g n = subgraph g (filter (/= n) $ neighbors g n)
21 maximalClique :: Graph -> [Node] -> [[Node]]
22 maximalClique _ [] = [[]]
23 maximalClique _ [n] = [[n]]
25 cliqueFinder :: Graph -> [[Node]]
26 cliqueFinder = undefined
30 ------------------------------------------------------------------------
31 -- TODO: filter subset de cliques
32 maxClique :: Graph -> [[Node]]
33 maxClique g = filterClique g
34 $ map (maxCliqueOn g) (nodes g)
36 ------------------------------------------------------------------------
40 filterClique :: Graph -> [Set.Set Node] -> [Set.Set Node]
41 filterClique = undefined
43 ------------------------------------------------------------------------
45 type CliqueMax = [Node]
47 maxCliqueOn :: Graph -> Node -> [CliqueMax]
48 maxCliqueOn = undefined
50 maxCliqueOn' :: Graph -> Node -> [Node] -> [CliqueMax]
51 maxCliqueOn' g n [] = [[n]]
52 maxCliqueOn' g n [m] = if (neighbors g n = [m])
54 else maxCliqueOn' g n [] <> maxCliqueOn' g m []
55 maxCliqueOn' g n (x:xs) = undefined
58 stopClique :: Graph -> Node -> [Node] -> [Node]
59 -- no self, no reflexivity
60 stopClique _ n [] = [n]
62 stopClique g n [m] = if (neighbors g n) == [m]
65 stopClique g n ns = case all (\n' -> clique g n == clique g n') (x:xs) of
67 -- False -> stopClique g x xs
68 False -> stopClique g x xs
72 subGraph :: Graph -> Node -> Graph
73 subGraph g n = mkGraphUfromEdges (edges voisin <> edges g n)
76 ------------------------------------------------------------------------
80 sortWith :: (Node -> Node -> Ord) -> Graph -> [Node] -> [Node]
81 sortWith f g ns = undefined
84 sort :: Graph -> [Node] -> [Node]
86 sort g ns = sortOn (degree g) ns
88 areEdged = areNeighbors
89 areNeighbors :: Graph -> Node -> Node -> Bool
90 areNeighbors g n m = neighbors g n == [m]
92 ------------------------------------------------------------------------
95 -- test_graph = mkGraphUfromEdges [(1,1), (2,2), (3,3)]
96 test_graph = mkGraphUfromEdges [(1,2), (3,3)]
99 test_graph' = mkGraphUfromEdges [(1,2), (3,3), (3,2)]
101 test_graph'' :: Graph
102 test_graph'' = mkGraphUfromEdges [(1,2), (2,3), (1,3)]
104 test_graph''' :: Graph
105 test_graph''' = mkGraphUfromEdges [ (4,1)