{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Math.Grads.Algo.Isomorphism
( EComparator, VComparator
, GComparable(..)
, VertexIndex
, getIso
, getMultiIso
, isIso
, isIsoSub
) where
import Data.Map (Map)
import Data.Maybe (isJust, listToMaybe)
import qualified Math.Grads.Algo.Isomorphism.RI as RI
import Math.Grads.Algo.Isomorphism.Types (EComparator,
GComparable (..),
VComparator, VertexIndex)
import Math.Grads.GenericGraph (GenericGraph (..))
import Math.Grads.Graph (toList)
isIso :: (Ord v1, Ord v2, GComparable GenericGraph v1 e1 GenericGraph v2 e2, Eq e1, Eq e2)
=> GenericGraph v1 e1
-> GenericGraph v2 e2
-> Bool
isIso queryGraph targetGraph = res
where
(v1, e1) = toList queryGraph
(v2, e2) = toList targetGraph
isoSub = isIsoSub queryGraph targetGraph
res = length v1 == length v2 && length e1 == length e2 && isoSub
isIsoSub :: (Ord v1, Ord v2, GComparable GenericGraph v1 e1 GenericGraph v2 e2, Eq e1, Eq e2)
=> GenericGraph v1 e1
-> GenericGraph v2 e2
-> Bool
isIsoSub queryGraph targetGraph = isJust $ getIso queryGraph targetGraph
getIso :: (Ord v1, Ord v2, GComparable GenericGraph v1 e1 GenericGraph v2 e2, Eq e1, Eq e2)
=> GenericGraph v1 e1
-> GenericGraph v2 e2
-> Maybe (Map Int Int)
getIso queryGraph targetGraph = listToMaybe $ getMultiIso queryGraph targetGraph
getMultiIso :: (Ord v1, Ord v2, GComparable GenericGraph v1 e1 GenericGraph v2 e2, Eq e1, Eq e2)
=> GenericGraph v1 e1
-> GenericGraph v2 e2
-> [Map Int Int]
getMultiIso = RI.getMultiIso