import Data.Serialize
import Data.Singletons (SingI)
+import Gargantext.Core.Viz.Graph.Index
+import Graph.Types (ClusterNode(..))
import IGraph hiding (mkGraph, neighbors, edges, nodes, Node, Graph)
import Protolude
-import Gargantext.Core.Viz.Graph.Index
-import Graph.Types
import qualified Data.List as List
+import qualified Data.Map as Map
import qualified IGraph as IG
import qualified IGraph.Algorithms.Clique as IG
import qualified IGraph.Algorithms.Community as IG
import qualified IGraph.Algorithms.Structure as IG
import qualified IGraph.Random as IG
-import qualified Data.Map as Map
------------------------------------------------------------------
-- | Main Types
spinglass s g = toClusterNode
<$> map catMaybes
<$> map (map (\n -> Map.lookup n fromI))
- <$> partitions_spinglass' s g'''
+ <$> List.concat
+ <$> mapM (partitions_spinglass' s) g'
where
- g' = toIndex toI g
- g'' = mkGraphUfromEdges (Map.keys g')
- g''' = case IG.isConnected g'' of
- True -> g''
- False -> case head (IG.decompose g'') of
- Nothing -> panic "[G.C.V.G.T.Igraph: not connected graph]"
- Just g'''' -> g''''
+ -- Not connected components of the graph make crash spinglass
+ g' = IG.decompose $ mkGraphUfromEdges
+ $ Map.keys
+ $ toIndex toI g
(toI, fromI) = createIndices g
+
-- | Tools to analyze graphs
partitions_spinglass' :: (Serialize v, Serialize e)
=> Seed -> IG.Graph 'U v e -> IO [[Int]]