module Analysis.CriticalSequence
( CriticalSequenceType (..),
CriticalSequence,
getCriticalSequenceMatches,
getCriticalSequenceComatches,
getNacMatchOfCriticalSequence,
getNacIndexOfCriticalSequence,
getCriticalSequenceType,
findTriggeringCriticalSequences,
namedCriticalSequences,
findAllProduceUse,
findAllRemoveDangling,
findAllDeleteForbid,
findAllDeliverDelete,
findAllForbidProduce,
findAllDeliverDangling,
findAllProduceUseAndRemoveDangling,
) where
import Abstract.AdhesiveHLR as RW
import Abstract.DPO as RW hiding (calculateComatch)
import Analysis.CriticalPairs (findPotentialCriticalPairs)
import Analysis.DiagramAlgorithms
import Data.Maybe (mapMaybe)
data CriticalSequenceType =
ProduceUse
| RemoveDangling
| DeleteForbid
| DeliverDelete
| DeliverDangling
| ForbidProduce
deriving (Eq,Show)
type NamedRule m = (String, Production m)
type NamedCriticalPairs m = (String,String,[CriticalSequence m])
data CriticalSequence m = CriticalSequence {
matches :: Maybe (m, m),
comatches :: (m, m),
nac :: Maybe (m, Int),
csType :: CriticalSequenceType
} deriving (Eq,Show)
getCriticalSequenceMatches :: CriticalSequence m -> Maybe (m, m)
getCriticalSequenceMatches = matches
getCriticalSequenceComatches :: CriticalSequence m -> (m, m)
getCriticalSequenceComatches = comatches
getCriticalSequenceType :: CriticalSequence m -> CriticalSequenceType
getCriticalSequenceType = csType
getNacMatchOfCriticalSequence :: CriticalSequence m -> Maybe m
getNacMatchOfCriticalSequence cs =
case nac cs of
Just (nac,_) -> Just nac
Nothing -> Nothing
getNacIndexOfCriticalSequence :: CriticalSequence m -> Maybe Int
getNacIndexOfCriticalSequence cs =
case nac cs of
Just (_,idx) -> Just idx
Nothing -> Nothing
namedCriticalSequences :: (EpiPairs m, DPO m) => MorphismsConfig -> [NamedRule m] -> [NamedCriticalPairs m]
namedCriticalSequences conf rules =
map (uncurry getCSs) [(a,b) | a <- rules, b <- rules]
where
getCSs (n1,r1) (n2,r2) = (n1, n2, findCriticalSequences conf r1 r2)
findTriggeringCriticalSequences :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findTriggeringCriticalSequences conf p1 p2 =
findAllProduceUseAndRemoveDangling conf p1 p2 ++
findAllDeleteForbid conf p1 p2
findCriticalSequences :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findCriticalSequences conf p1 p2 =
findAllProduceUseAndRemoveDangling conf p1 p2 ++
findAllDeleteForbid conf p1 p2 ++
findAllDeliverDelete conf p1 p2 ++
findAllDeliverDangling conf p1 p2 ++
findAllForbidProduce conf p1 p2
findAllProduceUse :: (DPO m, EpiPairs m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllProduceUse conf p1 p2 =
map (\m -> CriticalSequence Nothing m Nothing ProduceUse) prodUse
where
p1' = invertProduction conf p1
gluing = findPotentialCriticalPairs conf p1' p2
prodUse = filter (isDeleteUse conf p1') gluing
findAllRemoveDangling :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllRemoveDangling conf p1 p2 =
map (\m -> CriticalSequence Nothing m Nothing RemoveDangling) remDang
where
p1' = invertProduction conf p1
gluing = findPotentialCriticalPairs conf p1' p2
remDang = filter (isProduceDangling conf p1' p2) gluing
findAllProduceUseAndRemoveDangling :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllProduceUseAndRemoveDangling conf p1 p2 =
map categorizeDependency dependencies
where
p1' = invertProduction conf p1
gluing = findPotentialCriticalPairs conf p1' p2
dependencies = mapMaybe (deleteUseDangling conf p1' p2) gluing
categorizeDependency x = case x of
(Left m) -> CriticalSequence Nothing m Nothing ProduceUse
(Right m) -> CriticalSequence Nothing m Nothing RemoveDangling
findAllDeleteForbid :: (DPO m, EpiPairs m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllDeleteForbid conf p1 p2 =
concatMap (findDeleteForbidForNAC conf p1' p2) (zip (getNACs p2) [0..])
where
p1' = invertProduction conf p1
findDeleteForbidForNAC :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> (m, Int) -> [CriticalSequence m]
findDeleteForbidForNAC conf p1' p2 nac =
map
(\(m',m,nac) -> CriticalSequence (Just m) m' (Just nac) DeleteForbid)
(produceForbidOneNac conf p1' p2 nac)
findAllDeliverDelete :: (DPO m, EpiPairs m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllDeliverDelete conf p1 p2 =
map (\m -> CriticalSequence Nothing m Nothing DeliverDelete) delDel
where
p1' = invertProduction conf p1
gluing = findPotentialCriticalPairs conf p1' p2
delDel = filter (\(m1,m2) -> isDeleteUse conf p2 (m2,m1)) gluing
findAllDeliverDangling :: (DPO m, EpiPairs m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllDeliverDangling conf p1 p2 =
map (\m -> CriticalSequence Nothing m Nothing DeliverDangling) delDang
where
p1' = invertProduction conf p1
gluing = findPotentialCriticalPairs conf p1' p2
delDang = filter (\(m1,m2) -> isProduceDangling conf p2 p1' (m2,m1)) gluing
findAllForbidProduce :: (DPO m, EpiPairs m) => MorphismsConfig -> Production m -> Production m -> [CriticalSequence m]
findAllForbidProduce conf p1 p2 =
concatMap (findForbidProduceForNAC conf p1' p2) (zip (getNACs p1') [0..])
where
p1' = invertProduction conf p1
findForbidProduceForNAC :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> (m, Int) -> [CriticalSequence m]
findForbidProduceForNAC conf p1' p2 nac =
map
(\(m,m',nac) -> CriticalSequence (Just m) m' (Just nac) ForbidProduce)
(produceForbidOneNac conf p2 p1' nac)