module Analysis.DiagramAlgorithms (
isDeleteUse
, isProduceDangling
, isProduceForbid
, isProduceUse
, isDeleteForbid
, deleteUseDangling
, produceForbidOneNac
, findAllPossibleH21
) where
import Abstract.AdhesiveHLR
import Abstract.DPO
import Abstract.Morphism
import Control.Applicative
import Control.Monad
isDeleteUse :: DPO m => MorphismsConfig -> Production m -> (m, m) -> Bool
isDeleteUse conf p1 (m1,m2) = null h21
where
(_,d1) = calculatePushoutComplement m1 (getLHS p1)
h21 = findAllPossibleH21 conf m2 d1
isProduceUse :: DPO m => MorphismsConfig -> Production m -> (m, m) -> Bool
isProduceUse conf p1 (m1',m2) = null h21
where
(_,e1) = calculatePushoutComplement m1' (getRHS p1)
h21 = findAllPossibleH21 conf m2 e1
getH21fromRewriting :: DPO m => MorphismsConfig -> Production m -> m -> m -> ([m], m)
getH21fromRewriting conf p1 m1 m2 = (h21,h21_e1)
where
(k1,d1) = calculatePushoutComplement m1 (getLHS p1)
(_,e1) = calculatePushout k1 (getRHS p1)
h21 = findAllPossibleH21 conf m2 d1
h21_e1 = compose (head h21) e1
isProduceDangling :: DPO m => MorphismsConfig -> Production m -> Production m -> (m, m) -> Bool
isProduceDangling conf p1 p2 (m1,m2) =
let (h21,h21_e1) = getH21fromRewriting conf p1 m1 m2
in not (null h21) && not (satisfiesGluingConditions conf p2 h21_e1) && satisfiesNACs conf p2 h21_e1
isProduceForbid :: (DPO m) => MorphismsConfig -> Production m -> Production m -> (m,m) -> Bool
isProduceForbid conf p1 p2 (m1,m2) =
let (h21,h21_e1) = getH21fromRewriting conf p1 m1 m2
in not (null h21) && satisfiesGluingConditions conf p2 h21_e1 && not (satisfiesNACs conf p2 h21_e1)
isDeleteForbid :: DPO m => MorphismsConfig -> Production m -> Production m -> (m,m) -> Bool
isDeleteForbid conf p1 p2 (m1',m2) =
let
validRewriting = hasPushoutComplement (Monomorphism, m1') (Monomorphism, getRHS p1)
(k1,e1) = calculatePushoutComplement m1' (getRHS p1)
h21 = findAllPossibleH21 conf m2 e1
(_,d1) = calculatePushout k1 (getLHS p1)
h21_d1 = compose (head h21) d1
in validRewriting && not (null h21) && satisfiesGluingConditions conf p2 h21_d1 && not (satisfiesNACs conf p2 h21_d1)
findAllPossibleH21 :: DPO m => MorphismsConfig -> m -> m -> [m]
findAllPossibleH21 conf m2 d1 =
if length h21 > 1
then error "produceDangling: non unique h21 morphism"
else h21
where
morphismRestriction = matchRestrictionToMorphismType (matchRestriction conf)
h21 = findCospanCommuter morphismRestriction m2 d1
deleteUseDangling :: DPO m => MorphismsConfig -> Production m -> Production m -> (m, m)-> Maybe (Either (m,m) (m,m))
deleteUseDangling conf p1 p2 (m1,m2) =
case (null h21, dangling) of
(True,_) -> Just (Left (m1,m2))
(False,True) -> Just (Right (m1,m2))
_ -> Nothing
where
(h21,h21_e1) = getH21fromRewriting conf p1 m1 m2
dangling = not (satisfiesGluingConditions conf p2 h21_e1) && satisfiesNACs conf p2 h21_e1
produceForbidOneNac :: (EpiPairs m, DPO m) => MorphismsConfig -> Production m -> Production m -> (m, Int) -> [((m,m), (m,m), (m,Int))]
produceForbidOneNac conf p1 p2 (n2,idx) = do
let p1' = invertProduction conf p1
(m1', q21) <- createJointlyEpimorphicPairsFromNAC conf (codomain $ getRHS p1) n2
guard (satisfiesRewritingConditions conf p1' m1')
let (k1, m1, e1, d1) = calculateDPO m1' p1'
guard (satisfiesNACs conf p1 m1)
let h21Candidates = findMorphisms' conf (domain n2) (codomain k1)
composeNQ21 = compose n2 q21
case filter (\h21 -> compose h21 e1 == composeNQ21) h21Candidates of
[] ->
empty
[h21] -> do
let m2 = compose h21 d1
m2' = compose h21 e1
guard (satisfiesRewritingConditions conf p2 m2)
return ((m1, m2), (m1', m2'), (q21, idx))
_ -> error "produceForbidOneNac: h21 should be unique, but isn't"
findMorphisms' :: FindMorphism m => MorphismsConfig -> Obj m -> Obj m -> [m]
findMorphisms' conf =
findMorphisms (matchRestrictionToMorphismType $ matchRestriction conf)