module Analysis.Interlevel.EvolutionarySpans
( allEvolSpans
, EvoSpan()
, leftMatch
, rightMatch
, cpe
) where
import Abstract.AdhesiveHLR
import Abstract.DPO
import Abstract.Valid
import Analysis.DiagramAlgorithms
import SndOrder.Morphism
import SndOrder.Rule
type CPE = (Bool, Bool)
data EvoSpan a b = EvoSpan {
leftMatch :: RuleMorphism a b,
rightMatch :: RuleMorphism a b,
cpe :: CPE
} deriving (Eq,Show)
allEvolSpans :: MorphismsConfig -> [(String, SndOrderRule a b)] -> [(String, String, [EvoSpan a b])]
allEvolSpans _ [] = []
allEvolSpans dpoConf rules@(r:rs) = map (evolSpans dpoConf r) rules ++ allEvolSpans dpoConf rs
evolSpans :: MorphismsConfig -> (String, SndOrderRule a b) -> (String, SndOrderRule a b) -> (String, String, [EvoSpan a b])
evolSpans conf (n1,r1) (n2,r2) = (n1, n2, spans)
where
spans = map (\m@(m1,m2) -> EvoSpan m1 m2 (classify conf r1 r2 m)) xs''
r1Left = codomain (getLHS r1)
r2Left = codomain (getLHS r2)
r1Right = codomain (getRHS r1)
r2Right = codomain (getRHS r2)
leftR1 = buildProduction (mappingLeft (getLHS r1)) (mappingLeft (getRHS r1)) []
leftR2 = buildProduction (mappingLeft (getLHS r2)) (mappingLeft (getRHS r2)) []
pairs = createJointlyEpimorphicPairs (matchRestriction conf == MonoMatches) leftR1 leftR2
xs = filter (\(m1,_) -> isValid (codomain m1)) pairs
xs' = filter (\(m1,m2) -> satisfyRewritingConditions conf (r1Left, mappingLeft m1) (r2Left, mappingLeft m2)) xs
xs'' = filter (\(m1,m2) -> satisfyRewritingConditions conf (r1Right, mappingLeft m1) (r2Right, mappingLeft m2)) xs'
classify :: MorphismsConfig -> SndOrderRule a b -> SndOrderRule a b -> (RuleMorphism a b, RuleMorphism a b) -> CPE
classify conf r1 r2 (m1,m2) = (deleteUseFlGl, deleteUseFlGl'')
where
isConflict c l1 l2 m =
isDeleteUse c l1 m
|| isProduceDangling c l1 l2 m
|| isProduceForbid c l1 l2 m
deleteUseFlGl =
isConflict conf
(codomain (getLHS r1))
(codomain (getLHS r2))
(mappingLeft m1, mappingLeft m2) ||
isConflict conf
(codomain (getLHS r2))
(codomain (getLHS r1))
(mappingLeft m2, mappingLeft m1)
deleteUseFlGl'' =
isConflict conf
(codomain (getRHS r1))
(codomain (getRHS r2))
(mappingRight m1, mappingRight m2) ||
isConflict conf
(codomain (getRHS r2))
(codomain (getRHS r1))
(mappingRight m2, mappingRight m1)