module DDC.Core.Flow.Transform.Rates.Clusters.Base where
import DDC.Core.Flow.Transform.Rates.Graph
type TransducerMap n = n -> n -> Maybe (n,n)
noFusionPreventingPath :: (Ord n) => [((n,n),Bool)] -> n -> n -> Bool
noFusionPreventingPath arcs u v
= all (all snd) (paths u v)
&& all (all snd) (paths v u)
where
paths w x
| w == x
= [[]]
| otherwise
= let outs = filter (\((i,_j),_f) -> i == w) arcs
in concatMap (\((w',j),f) -> map (((w',j),f):) (paths j x)) outs
typeComparable :: (Ord n, Eq t) => Graph n t -> TransducerMap n -> n -> n -> Bool
typeComparable g trans a b
= case (nodeType g a, nodeType g b) of
(Just a', Just b')
-> if a' == b'
then True
else case trans a b of
Just _ -> True
Nothing -> False
_
-> False