Powerset.hs 1.22 KB
Newer Older
1
{-# LANGUAGE InstanceSigs #-}
Hans-Peter Deifel's avatar
Hans-Peter Deifel committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}

module Data.Functors.Powerset where

import           Data.Vector (Vector)
import qualified Data.Vector as V
import qualified Data.Yaml as Yaml

import           Data.RefinementInterface
import qualified Data.MorphismEncoding as Encoding

data Powerset = Powerset
  deriving (Show)

instance RefinementInterface Powerset where
  type Label Powerset = ()
  type Weight Powerset = (Int, Int)
  type H1 Powerset = Bool
  type H3 Powerset = (Bool, Bool, Bool)

  parse _ = Yaml.withArray "Morphisms" $ \arr -> do
    succsessors <- V.imapM parseNode arr

    let structure = V.map (not . V.null . snd) succsessors
28
        edges = V.concatMap (\(from, succs) -> fmap (Encoding.Edge from ()) succs) succsessors
Hans-Peter Deifel's avatar
Hans-Peter Deifel committed
29
30
31
32
33
34
35

    return $ Encoding.new structure edges

    where
      parseNode :: Int -> Yaml.Value -> Yaml.Parser (Int, Vector Int)
      parseNode nodeIdx value = (nodeIdx,) <$> Yaml.parseJSON value

36
37
38
  init :: Powerset -> H1 Powerset -> [Label Powerset] -> Weight Powerset
  init _ _ = (0, ) . length

Hans-Peter Deifel's avatar
Hans-Peter Deifel committed
39
40
41
42
43
powerset :: RefinableFunctor
powerset = RefinableFunctor
  { name = "Powerset"
  , parseArguments = NoArguments Powerset
  }