module Algebra.Graph.Bipartite.AdjacencyMap (
AdjacencyMap, leftAdjacencyMap, rightAdjacencyMap,
empty, leftVertex, rightVertex, vertex, edge, overlay, connect, vertices,
edges, overlays, connects, swap,
toBipartite, toBipartiteWith, fromBipartite, fromBipartiteWith,
isEmpty, hasLeftVertex, hasRightVertex, hasVertex, hasEdge, leftVertexCount,
rightVertexCount, vertexCount, edgeCount, leftVertexList, rightVertexList,
vertexList, edgeList, leftVertexSet, rightVertexSet, vertexSet, edgeSet,
leftAdjacencyList, rightAdjacencyList,
List (..), evenList, oddList, path, circuit, biclique, star, stars, mesh,
removeLeftVertex, removeRightVertex, removeEdge, bimap,
box, boxWith,
consistent
) where
import Control.Monad
import Control.Monad.Trans.Maybe
import Control.Monad.Trans.State
import Data.Either
import Data.Foldable (asum)
import Data.List ((\\), sort)
import Data.Map.Strict (Map)
import Data.Maybe
import Data.Set (Set)
import GHC.Exts (IsList(..))
import GHC.Generics
import qualified Algebra.Graph as G
import qualified Algebra.Graph.AdjacencyMap as AM
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Tuple
data AdjacencyMap a b = BAM {
forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap :: Map a (Set b),
forall a b. AdjacencyMap a b -> Map b (Set a)
rightAdjacencyMap :: Map b (Set a)
} deriving forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (AdjacencyMap a b) x -> AdjacencyMap a b
forall a b x. AdjacencyMap a b -> Rep (AdjacencyMap a b) x
$cto :: forall a b x. Rep (AdjacencyMap a b) x -> AdjacencyMap a b
$cfrom :: forall a b x. AdjacencyMap a b -> Rep (AdjacencyMap a b) x
Generic
instance (Ord a, Ord b, Num b) => Num (AdjacencyMap a b) where
fromInteger :: Integer -> AdjacencyMap a b
fromInteger = forall b a. b -> AdjacencyMap a b
rightVertex forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger
+ :: AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
(+) = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
overlay
* :: AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
(*) = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
connect
signum :: AdjacencyMap a b -> AdjacencyMap a b
signum = forall a b. a -> b -> a
const forall a b. AdjacencyMap a b
empty
abs :: AdjacencyMap a b -> AdjacencyMap a b
abs = forall a. a -> a
id
negate :: AdjacencyMap a b -> AdjacencyMap a b
negate = forall a. a -> a
id
instance (Ord a, Ord b) => Eq (AdjacencyMap a b) where
BAM Map a (Set b)
ab1 Map b (Set a)
ba1 == :: AdjacencyMap a b -> AdjacencyMap a b -> Bool
== BAM Map a (Set b)
ab2 Map b (Set a)
ba2 = Map a (Set b)
ab1 forall a. Eq a => a -> a -> Bool
== Map a (Set b)
ab2 Bool -> Bool -> Bool
&& forall k a. Map k a -> Set k
Map.keysSet Map b (Set a)
ba1 forall a. Eq a => a -> a -> Bool
== forall k a. Map k a -> Set k
Map.keysSet Map b (Set a)
ba2
instance (Ord a, Ord b) => Ord (AdjacencyMap a b) where
compare :: AdjacencyMap a b -> AdjacencyMap a b -> Ordering
compare AdjacencyMap a b
x AdjacencyMap a b
y = forall a. Monoid a => [a] -> a
mconcat
[ forall a. Ord a => a -> a -> Ordering
compare (forall a b. AdjacencyMap a b -> Int
vertexCount AdjacencyMap a b
x) (forall a b. AdjacencyMap a b -> Int
vertexCount AdjacencyMap a b
y)
, forall a. Ord a => a -> a -> Ordering
compare (forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (Either a b)
vertexSet AdjacencyMap a b
x) (forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (Either a b)
vertexSet AdjacencyMap a b
y)
, forall a. Ord a => a -> a -> Ordering
compare (forall a b. AdjacencyMap a b -> Int
edgeCount AdjacencyMap a b
x) (forall a b. AdjacencyMap a b -> Int
edgeCount AdjacencyMap a b
y)
, forall a. Ord a => a -> a -> Ordering
compare (forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (a, b)
edgeSet AdjacencyMap a b
x) (forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (a, b)
edgeSet AdjacencyMap a b
y) ]
instance (Ord a, Ord b, Show a, Show b) => Show (AdjacencyMap a b) where
showsPrec :: Int -> AdjacencyMap a b -> ShowS
showsPrec Int
p AdjacencyMap a b
g
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
as Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [b]
bs = String -> ShowS
showString String
"empty"
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(a, b)]
es = Bool -> ShowS -> ShowS
showParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ forall {a} {a}. (Show a, Show a) => [a] -> [a] -> ShowS
vShow [a]
as [b]
bs
| ([a]
as forall a. Eq a => a -> a -> Bool
== [a]
aUsed) Bool -> Bool -> Bool
&& ([b]
bs forall a. Eq a => a -> a -> Bool
== [b]
bUsed) = Bool -> ShowS -> ShowS
showParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$ forall {a} {a}. (Show a, Show a) => [(a, a)] -> ShowS
eShow [(a, b)]
es
| Bool
otherwise = Bool -> ShowS -> ShowS
showParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10)
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"overlay ("
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. (Show a, Show a) => [Either a a] -> ShowS
veShow ([Either a b]
vs forall a. Eq a => [a] -> [a] -> [a]
\\ [Either a b]
used)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
") ("
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a} {a}. (Show a, Show a) => [(a, a)] -> ShowS
eShow [(a, b)]
es
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
")"
where
as :: [a]
as = forall a b. AdjacencyMap a b -> [a]
leftVertexList AdjacencyMap a b
g
bs :: [b]
bs = forall a b. AdjacencyMap a b -> [b]
rightVertexList AdjacencyMap a b
g
vs :: [Either a b]
vs = forall a b. AdjacencyMap a b -> [Either a b]
vertexList AdjacencyMap a b
g
es :: [(a, b)]
es = forall a b. AdjacencyMap a b -> [(a, b)]
edgeList AdjacencyMap a b
g
aUsed :: [a]
aUsed = forall a. Set a -> [a]
Set.toAscList forall a b. (a -> b) -> a -> b
$ forall a. Eq a => [a] -> Set a
Set.fromAscList [ a
a | (a
a, b
_) <- forall a b. AdjacencyMap a b -> [(a, b)]
edgeList AdjacencyMap a b
g ]
bUsed :: [b]
bUsed = forall a. Set a -> [a]
Set.toAscList forall a b. (a -> b) -> a -> b
$ forall a. Eq a => [a] -> Set a
Set.fromAscList [ b
b | (b
b, a
_) <- forall a b. AdjacencyMap a b -> [(a, b)]
edgeList (forall a b. AdjacencyMap a b -> AdjacencyMap b a
swap AdjacencyMap a b
g) ]
used :: [Either a b]
used = forall a b. (a -> b) -> [a] -> [b]
map forall a b. a -> Either a b
Left [a]
aUsed forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall a b. b -> Either a b
Right [b]
bUsed
vShow :: [a] -> [a] -> ShowS
vShow [a
a] [] = String -> ShowS
showString String
"leftVertex " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
a
vShow [] [a
b] = String -> ShowS
showString String
"rightVertex " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
b
vShow [a]
as [a]
bs = String -> ShowS
showString String
"vertices " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [a]
as
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [a]
bs
eShow :: [(a, a)] -> ShowS
eShow [(a
a, a
b)] = String -> ShowS
showString String
"edge " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
" " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
b
eShow [(a, a)]
es = String -> ShowS
showString String
"edges " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [(a, a)]
es
veShow :: [Either a a] -> ShowS
veShow [Either a a]
xs = forall {a} {a}. (Show a, Show a) => [a] -> [a] -> ShowS
vShow (forall a b. [Either a b] -> [a]
lefts [Either a a]
xs) (forall a b. [Either a b] -> [b]
rights [Either a a]
xs)
instance (Ord a, Ord b) => Semigroup (AdjacencyMap a b) where
<> :: AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
(<>) = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
overlay
instance (Ord a, Ord b) => Monoid (AdjacencyMap a b) where
mempty :: AdjacencyMap a b
mempty = forall a b. AdjacencyMap a b
empty
empty :: AdjacencyMap a b
empty :: forall a b. AdjacencyMap a b
empty = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM forall k a. Map k a
Map.empty forall k a. Map k a
Map.empty
leftVertex :: a -> AdjacencyMap a b
leftVertex :: forall a b. a -> AdjacencyMap a b
leftVertex a
a = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. k -> a -> Map k a
Map.singleton a
a forall a. Set a
Set.empty) forall k a. Map k a
Map.empty
rightVertex :: b -> AdjacencyMap a b
rightVertex :: forall b a. b -> AdjacencyMap a b
rightVertex b
b = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM forall k a. Map k a
Map.empty (forall k a. k -> a -> Map k a
Map.singleton b
b forall a. Set a
Set.empty)
vertex :: Either a b -> AdjacencyMap a b
vertex :: forall a b. Either a b -> AdjacencyMap a b
vertex (Left a
a) = forall a b. a -> AdjacencyMap a b
leftVertex a
a
vertex (Right b
b) = forall b a. b -> AdjacencyMap a b
rightVertex b
b
edge :: a -> b -> AdjacencyMap a b
edge :: forall a b. a -> b -> AdjacencyMap a b
edge a
a b
b =
forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. k -> a -> Map k a
Map.singleton a
a (forall a. a -> Set a
Set.singleton b
b)) (forall k a. k -> a -> Map k a
Map.singleton b
b (forall a. a -> Set a
Set.singleton a
a))
overlay :: (Ord a, Ord b) => AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
overlay :: forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
overlay (BAM Map a (Set b)
ab1 Map b (Set a)
ba1) (BAM Map a (Set b)
ab2 Map b (Set a)
ba2) =
forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a. Ord a => Set a -> Set a -> Set a
Set.union Map a (Set b)
ab1 Map a (Set b)
ab2) (forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith forall a. Ord a => Set a -> Set a -> Set a
Set.union Map b (Set a)
ba1 Map b (Set a)
ba2)
connect :: (Ord a, Ord b) => AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
connect :: forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
connect (BAM Map a (Set b)
ab1 Map b (Set a)
ba1) (BAM Map a (Set b)
ab2 Map b (Set a)
ba2) = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM Map a (Set b)
ab Map b (Set a)
ba
where
a1 :: Set a
a1 = forall k a. Map k a -> Set k
Map.keysSet Map a (Set b)
ab1
a2 :: Set a
a2 = forall k a. Map k a -> Set k
Map.keysSet Map a (Set b)
ab2
b1 :: Set b
b1 = forall k a. Map k a -> Set k
Map.keysSet Map b (Set a)
ba1
b2 :: Set b
b2 = forall k a. Map k a -> Set k
Map.keysSet Map b (Set a)
ba2
ab :: Map a (Set b)
ab = forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith forall a. Ord a => Set a -> Set a -> Set a
Set.union
[ Map a (Set b)
ab1, Map a (Set b)
ab2, forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set b
b2) Set a
a1, forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set b
b1) Set a
a2 ]
ba :: Map b (Set a)
ba = forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith forall a. Ord a => Set a -> Set a -> Set a
Set.union
[ Map b (Set a)
ba1, Map b (Set a)
ba2, forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set a
a2) Set b
b1, forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set a
a1) Set b
b2 ]
vertices :: (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap a b
vertices :: forall a b. (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap a b
vertices [a]
as [b]
bs = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [ (a
a, forall a. Set a
Set.empty) | a
a <- [a]
as ])
(forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [ (b
b, forall a. Set a
Set.empty) | b
b <- [b]
bs ])
edges :: (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
edges :: forall a b. (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
edges [(a, b)]
es = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith forall a. Ord a => Set a -> Set a -> Set a
Set.union [ (a
a, forall a. a -> Set a
Set.singleton b
b) | (a
a, b
b) <- [(a, b)]
es ])
(forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith forall a. Ord a => Set a -> Set a -> Set a
Set.union [ (b
b, forall a. a -> Set a
Set.singleton a
a) | (a
a, b
b) <- [(a, b)]
es ])
overlays :: (Ord a, Ord b) => [AdjacencyMap a b] -> AdjacencyMap a b
overlays :: forall a b.
(Ord a, Ord b) =>
[AdjacencyMap a b] -> AdjacencyMap a b
overlays [AdjacencyMap a b]
xs = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith forall a. Ord a => Set a -> Set a -> Set a
Set.union (forall a b. (a -> b) -> [a] -> [b]
map forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap [AdjacencyMap a b]
xs))
(forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
(a -> a -> a) -> f (Map k a) -> Map k a
Map.unionsWith forall a. Ord a => Set a -> Set a -> Set a
Set.union (forall a b. (a -> b) -> [a] -> [b]
map forall a b. AdjacencyMap a b -> Map b (Set a)
rightAdjacencyMap [AdjacencyMap a b]
xs))
connects :: (Ord a, Ord b) => [AdjacencyMap a b] -> AdjacencyMap a b
connects :: forall a b.
(Ord a, Ord b) =>
[AdjacencyMap a b] -> AdjacencyMap a b
connects = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
connect forall a b. AdjacencyMap a b
empty
swap :: AdjacencyMap a b -> AdjacencyMap b a
swap :: forall a b. AdjacencyMap a b -> AdjacencyMap b a
swap (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM Map b (Set a)
ba Map a (Set b)
ab
toBipartite :: (Ord a, Ord b) => AM.AdjacencyMap (Either a b) -> AdjacencyMap a b
toBipartite :: forall a b.
(Ord a, Ord b) =>
AdjacencyMap (Either a b) -> AdjacencyMap a b
toBipartite AdjacencyMap (Either a b)
g = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Eq k => [(k, a)] -> Map k a
Map.fromAscList [ (a
a, forall {a}. Set (Either a b) -> Set b
getRights Set (Either a b)
vs) | (Left a
a, Set (Either a b)
vs) <- [(Either a b, Set (Either a b))]
am ])
(forall k a. Eq k => [(k, a)] -> Map k a
Map.fromAscList [ (b
b, forall {b}. Set (Either a b) -> Set a
getLefts Set (Either a b)
vs) | (Right b
b, Set (Either a b)
vs) <- [(Either a b, Set (Either a b))]
am ])
where
getRights :: Set (Either a b) -> Set b
getRights = forall a. Eq a => [a] -> Set a
Set.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [Either a b] -> [b]
rights forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toAscList
getLefts :: Set (Either a b) -> Set a
getLefts = forall a. Eq a => [a] -> Set a
Set.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [Either a b] -> [a]
lefts forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toAscList
am :: [(Either a b, Set (Either a b))]
am = forall k a. Map k a -> [(k, a)]
Map.toAscList forall a b. (a -> b) -> a -> b
$ forall a. AdjacencyMap a -> Map a (Set a)
AM.adjacencyMap forall a b. (a -> b) -> a -> b
$ forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.symmetricClosure AdjacencyMap (Either a b)
g
toBipartiteWith :: (Ord a, Ord b, Ord c) => (a -> Either b c) -> AM.AdjacencyMap a -> AdjacencyMap b c
toBipartiteWith :: forall a b c.
(Ord a, Ord b, Ord c) =>
(a -> Either b c) -> AdjacencyMap a -> AdjacencyMap b c
toBipartiteWith a -> Either b c
f = forall a b.
(Ord a, Ord b) =>
AdjacencyMap (Either a b) -> AdjacencyMap a b
toBipartite forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap a -> Either b c
f
fromBipartite :: (Ord a, Ord b) => AdjacencyMap a b -> AM.AdjacencyMap (Either a b)
fromBipartite :: forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap (Either a b)
fromBipartite (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a. Ord a => [(a, Set a)] -> AdjacencyMap a
AM.fromAdjacencySets forall a b. (a -> b) -> a -> b
$
[ (forall a b. a -> Either a b
Left a
a, forall a b. (a -> b) -> Set a -> Set b
Set.mapMonotonic forall a b. b -> Either a b
Right Set b
bs) | (a
a, Set b
bs) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map a (Set b)
ab ] forall a. [a] -> [a] -> [a]
++
[ (forall a b. b -> Either a b
Right b
b, forall a b. (a -> b) -> Set a -> Set b
Set.mapMonotonic forall a b. a -> Either a b
Left Set a
as) | (b
b, Set a
as) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map b (Set a)
ba ]
fromBipartiteWith :: Ord c => (a -> c) -> (b -> c) -> AdjacencyMap a b -> AM.AdjacencyMap c
fromBipartiteWith :: forall c a b.
Ord c =>
(a -> c) -> (b -> c) -> AdjacencyMap a b -> AdjacencyMap c
fromBipartiteWith a -> c
f b -> c
g (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a. Ord a => [(a, Set a)] -> AdjacencyMap a
AM.fromAdjacencySets forall a b. (a -> b) -> a -> b
$
[ (a -> c
f a
a, forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map b -> c
g Set b
bs) | (a
a, Set b
bs) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map a (Set b)
ab ] forall a. [a] -> [a] -> [a]
++
[ (b -> c
g b
b, forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map a -> c
f Set a
as) | (b
b, Set a
as) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map b (Set a)
ba ]
isEmpty :: AdjacencyMap a b -> Bool
isEmpty :: forall a b. AdjacencyMap a b -> Bool
isEmpty (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall k a. Map k a -> Bool
Map.null Map a (Set b)
ab Bool -> Bool -> Bool
&& forall k a. Map k a -> Bool
Map.null Map b (Set a)
ba
hasLeftVertex :: Ord a => a -> AdjacencyMap a b -> Bool
hasLeftVertex :: forall a b. Ord a => a -> AdjacencyMap a b -> Bool
hasLeftVertex a
a (BAM Map a (Set b)
ab Map b (Set a)
_) = forall k a. Ord k => k -> Map k a -> Bool
Map.member a
a Map a (Set b)
ab
hasRightVertex :: Ord b => b -> AdjacencyMap a b -> Bool
hasRightVertex :: forall b a. Ord b => b -> AdjacencyMap a b -> Bool
hasRightVertex b
b (BAM Map a (Set b)
_ Map b (Set a)
ba) = forall k a. Ord k => k -> Map k a -> Bool
Map.member b
b Map b (Set a)
ba
hasVertex :: (Ord a, Ord b) => Either a b -> AdjacencyMap a b -> Bool
hasVertex :: forall a b.
(Ord a, Ord b) =>
Either a b -> AdjacencyMap a b -> Bool
hasVertex (Left a
a) = forall a b. Ord a => a -> AdjacencyMap a b -> Bool
hasLeftVertex a
a
hasVertex (Right b
b) = forall b a. Ord b => b -> AdjacencyMap a b -> Bool
hasRightVertex b
b
hasEdge :: (Ord a, Ord b) => a -> b -> AdjacencyMap a b -> Bool
hasEdge :: forall a b. (Ord a, Ord b) => a -> b -> AdjacencyMap a b -> Bool
hasEdge a
a b
b (BAM Map a (Set b)
ab Map b (Set a)
_) = (forall a. Ord a => a -> Set a -> Bool
Set.member b
b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup a
a Map a (Set b)
ab) forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just Bool
True
leftVertexCount :: AdjacencyMap a b -> Int
leftVertexCount :: forall a b. AdjacencyMap a b -> Int
leftVertexCount = forall k a. Map k a -> Int
Map.size forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap
rightVertexCount :: AdjacencyMap a b -> Int
rightVertexCount :: forall a b. AdjacencyMap a b -> Int
rightVertexCount = forall k a. Map k a -> Int
Map.size forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map b (Set a)
rightAdjacencyMap
vertexCount :: AdjacencyMap a b -> Int
vertexCount :: forall a b. AdjacencyMap a b -> Int
vertexCount AdjacencyMap a b
g = forall a b. AdjacencyMap a b -> Int
leftVertexCount AdjacencyMap a b
g forall a. Num a => a -> a -> a
+ forall a b. AdjacencyMap a b -> Int
rightVertexCount AdjacencyMap a b
g
edgeCount :: AdjacencyMap a b -> Int
edgeCount :: forall a b. AdjacencyMap a b -> Int
edgeCount = forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr (forall a. Num a => a -> a -> a
(+) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> Int
Set.size) Int
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap
leftVertexList :: AdjacencyMap a b -> [a]
leftVertexList :: forall a b. AdjacencyMap a b -> [a]
leftVertexList = forall k a. Map k a -> [k]
Map.keys forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap
rightVertexList :: AdjacencyMap a b -> [b]
rightVertexList :: forall a b. AdjacencyMap a b -> [b]
rightVertexList = forall k a. Map k a -> [k]
Map.keys forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map b (Set a)
rightAdjacencyMap
vertexList :: AdjacencyMap a b -> [Either a b]
vertexList :: forall a b. AdjacencyMap a b -> [Either a b]
vertexList AdjacencyMap a b
g = forall a b. (a -> b) -> [a] -> [b]
map forall a b. a -> Either a b
Left (forall a b. AdjacencyMap a b -> [a]
leftVertexList AdjacencyMap a b
g) forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall a b. b -> Either a b
Right (forall a b. AdjacencyMap a b -> [b]
rightVertexList AdjacencyMap a b
g)
edgeList :: AdjacencyMap a b -> [(a, b)]
edgeList :: forall a b. AdjacencyMap a b -> [(a, b)]
edgeList (BAM Map a (Set b)
ab Map b (Set a)
_) = [ (a
a, b
b) | (a
a, Set b
bs) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map a (Set b)
ab, b
b <- forall a. Set a -> [a]
Set.toAscList Set b
bs ]
leftVertexSet :: AdjacencyMap a b -> Set a
leftVertexSet :: forall a b. AdjacencyMap a b -> Set a
leftVertexSet = forall k a. Map k a -> Set k
Map.keysSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map a (Set b)
leftAdjacencyMap
rightVertexSet :: AdjacencyMap a b -> Set b
rightVertexSet :: forall a b. AdjacencyMap a b -> Set b
rightVertexSet = forall k a. Map k a -> Set k
Map.keysSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> Map b (Set a)
rightAdjacencyMap
vertexSet :: (Ord a, Ord b) => AdjacencyMap a b -> Set (Either a b)
vertexSet :: forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (Either a b)
vertexSet = forall a. Eq a => [a] -> Set a
Set.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> [Either a b]
vertexList
edgeSet :: (Ord a, Ord b) => AdjacencyMap a b -> Set (a, b)
edgeSet :: forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Set (a, b)
edgeSet = forall a. Eq a => [a] -> Set a
Set.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. AdjacencyMap a b -> [(a, b)]
edgeList
leftAdjacencyList :: AdjacencyMap a b -> [(a, [b])]
leftAdjacencyList :: forall a b. AdjacencyMap a b -> [(a, [b])]
leftAdjacencyList (BAM Map a (Set b)
ab Map b (Set a)
_) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Set a -> [a]
Set.toAscList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Map k a -> [(k, a)]
Map.toAscList Map a (Set b)
ab
rightAdjacencyList :: AdjacencyMap a b -> [(b, [a])]
rightAdjacencyList :: forall a b. AdjacencyMap a b -> [(b, [a])]
rightAdjacencyList (BAM Map a (Set b)
_ Map b (Set a)
ba) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Set a -> [a]
Set.toAscList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall k a. Map k a -> [(k, a)]
Map.toAscList Map b (Set a)
ba
data List a b = Nil | Cons a (List b a) deriving (List a b -> List a b -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall a b. (Eq a, Eq b) => List a b -> List a b -> Bool
/= :: List a b -> List a b -> Bool
$c/= :: forall a b. (Eq a, Eq b) => List a b -> List a b -> Bool
== :: List a b -> List a b -> Bool
$c== :: forall a b. (Eq a, Eq b) => List a b -> List a b -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a b x. Rep (List a b) x -> List a b
forall a b x. List a b -> Rep (List a b) x
$cto :: forall a b x. Rep (List a b) x -> List a b
$cfrom :: forall a b x. List a b -> Rep (List a b) x
Generic, List a b -> List a b -> Bool
List a b -> List a b -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a} {b}. (Ord a, Ord b) => Eq (List a b)
forall a b. (Ord a, Ord b) => List a b -> List a b -> Bool
forall a b. (Ord a, Ord b) => List a b -> List a b -> Ordering
forall a b. (Ord a, Ord b) => List a b -> List a b -> List a b
min :: List a b -> List a b -> List a b
$cmin :: forall a b. (Ord a, Ord b) => List a b -> List a b -> List a b
max :: List a b -> List a b -> List a b
$cmax :: forall a b. (Ord a, Ord b) => List a b -> List a b -> List a b
>= :: List a b -> List a b -> Bool
$c>= :: forall a b. (Ord a, Ord b) => List a b -> List a b -> Bool
> :: List a b -> List a b -> Bool
$c> :: forall a b. (Ord a, Ord b) => List a b -> List a b -> Bool
<= :: List a b -> List a b -> Bool
$c<= :: forall a b. (Ord a, Ord b) => List a b -> List a b -> Bool
< :: List a b -> List a b -> Bool
$c< :: forall a b. (Ord a, Ord b) => List a b -> List a b -> Bool
compare :: List a b -> List a b -> Ordering
$ccompare :: forall a b. (Ord a, Ord b) => List a b -> List a b -> Ordering
Ord, Int -> List a b -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall a b. (Show a, Show b) => Int -> List a b -> ShowS
forall a b. (Show a, Show b) => [List a b] -> ShowS
forall a b. (Show a, Show b) => List a b -> String
showList :: [List a b] -> ShowS
$cshowList :: forall a b. (Show a, Show b) => [List a b] -> ShowS
show :: List a b -> String
$cshow :: forall a b. (Show a, Show b) => List a b -> String
showsPrec :: Int -> List a b -> ShowS
$cshowsPrec :: forall a b. (Show a, Show b) => Int -> List a b -> ShowS
Show)
instance IsList (List a a) where
type Item (List a a) = a
fromList :: [Item (List a a)] -> List a a
fromList = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall a b. a -> List b a -> List a b
Cons forall a b. List a b
Nil
toList :: List a a -> [Item (List a a)]
toList List a a
Nil = []
toList (Cons a
a List a a
as) = a
a forall a. a -> [a] -> [a]
: forall l. IsList l => l -> [Item l]
toList List a a
as
evenList :: [(a, b)] -> List a b
evenList :: forall a b. [(a, b)] -> List a b
evenList = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\(a
a, b
b) -> forall a b. a -> List b a -> List a b
Cons a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. a -> List b a -> List a b
Cons b
b) forall a b. List a b
Nil
oddList :: a -> [(b, a)] -> List a b
oddList :: forall a b. a -> [(b, a)] -> List a b
oddList a
a = forall a b. a -> List b a -> List a b
Cons a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. [(a, b)] -> List a b
evenList
path :: (Ord a, Ord b) => List a b -> AdjacencyMap a b
path :: forall a b. (Ord a, Ord b) => List a b -> AdjacencyMap a b
path List a b
Nil = forall a b. AdjacencyMap a b
empty
path (Cons a
a List b a
Nil) = forall a b. a -> AdjacencyMap a b
leftVertex a
a
path List a b
abs = forall a b. (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
edges (forall a b. [a] -> [b] -> [(a, b)]
zip [a]
as [b]
bs forall a. [a] -> [a] -> [a]
++ forall a b. [a] -> [b] -> [(a, b)]
zip (forall a. Int -> [a] -> [a]
drop Int
1 [a]
as) [b]
bs)
where
([a]
as, [b]
bs) = forall a b. List a b -> ([a], [b])
split List a b
abs
split :: List a b -> ([a], [b])
split :: forall a b. List a b -> ([a], [b])
split List a b
xs = case List a b
xs of
List a b
Nil -> ([], [])
Cons a
a List b a
Nil -> ([a
a], [])
Cons a
a (Cons b
b List a b
abs) -> (a
a forall a. a -> [a] -> [a]
: [a]
as, b
b forall a. a -> [a] -> [a]
: [b]
bs) where ([a]
as, [b]
bs) = forall a b. List a b -> ([a], [b])
split List a b
abs
circuit :: (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
circuit :: forall a b. (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
circuit [] = forall a b. AdjacencyMap a b
empty
circuit [(a, b)]
xs = forall a b. (Ord a, Ord b) => [(a, b)] -> AdjacencyMap a b
edges forall a b. (a -> b) -> a -> b
$ [(a, b)]
xs forall a. [a] -> [a] -> [a]
++ forall a b. [a] -> [b] -> [(a, b)]
zip (forall a. Int -> [a] -> [a]
drop Int
1 forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
cycle [a]
as) [b]
bs
where
([a]
as, [b]
bs) = forall a b. [(a, b)] -> ([a], [b])
unzip [(a, b)]
xs
biclique :: (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap a b
biclique :: forall a b. (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap a b
biclique [a]
xs [b]
ys = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set b
sys) Set a
sxs) (forall k a. (k -> a) -> Set k -> Map k a
Map.fromSet (forall a b. a -> b -> a
const Set a
sxs) Set b
sys)
where
sxs :: Set a
sxs = forall a. Ord a => [a] -> Set a
Set.fromList [a]
xs
sys :: Set b
sys = forall a. Ord a => [a] -> Set a
Set.fromList [b]
ys
star :: (Ord a, Ord b) => a -> [b] -> AdjacencyMap a b
star :: forall a b. (Ord a, Ord b) => a -> [b] -> AdjacencyMap a b
star a
x [b]
ys = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap a b -> AdjacencyMap a b
connect (forall a b. a -> AdjacencyMap a b
leftVertex a
x) (forall a b. (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap a b
vertices [] [b]
ys)
stars :: (Ord a, Ord b) => [(a, [b])] -> AdjacencyMap a b
stars :: forall a b. (Ord a, Ord b) => [(a, [b])] -> AdjacencyMap a b
stars = forall a b.
(Ord a, Ord b) =>
[AdjacencyMap a b] -> AdjacencyMap a b
overlays forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall a b. (Ord a, Ord b) => a -> [b] -> AdjacencyMap a b
star)
removeLeftVertex :: Ord a => a -> AdjacencyMap a b -> AdjacencyMap a b
removeLeftVertex :: forall a b. Ord a => a -> AdjacencyMap a b -> AdjacencyMap a b
removeLeftVertex a
a (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Ord k => k -> Map k a -> Map k a
Map.delete a
a Map a (Set b)
ab) (forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Ord a => a -> Set a -> Set a
Set.delete a
a) Map b (Set a)
ba)
removeRightVertex :: Ord b => b -> AdjacencyMap a b -> AdjacencyMap a b
removeRightVertex :: forall b a. Ord b => b -> AdjacencyMap a b -> AdjacencyMap a b
removeRightVertex b
b (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall a. Ord a => a -> Set a -> Set a
Set.delete b
b) Map a (Set b)
ab) (forall k a. Ord k => k -> Map k a -> Map k a
Map.delete b
b Map b (Set a)
ba)
removeEdge :: (Ord a, Ord b) => a -> b -> AdjacencyMap a b -> AdjacencyMap a b
removeEdge :: forall a b.
(Ord a, Ord b) =>
a -> b -> AdjacencyMap a b -> AdjacencyMap a b
removeEdge a
a b
b (BAM Map a (Set b)
ab Map b (Set a)
ba) =
forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM (forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (forall a. Ord a => a -> Set a -> Set a
Set.delete b
b) a
a Map a (Set b)
ab) (forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (forall a. Ord a => a -> Set a -> Set a
Set.delete a
a) b
b Map b (Set a)
ba)
bimap :: (Ord a, Ord b, Ord c, Ord d) => (a -> c) -> (b -> d) -> AdjacencyMap a b -> AdjacencyMap c d
bimap :: forall a b c d.
(Ord a, Ord b, Ord c, Ord d) =>
(a -> c) -> (b -> d) -> AdjacencyMap a b -> AdjacencyMap c d
bimap a -> c
f b -> d
g (BAM Map a (Set b)
ab Map b (Set a)
ba) = forall a b. Map a (Set b) -> Map b (Set a) -> AdjacencyMap a b
BAM Map c (Set d)
cd Map d (Set c)
dc
where
cd :: Map c (Set d)
cd = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map b -> d
g) forall a b. (a -> b) -> a -> b
$ forall k2 a k1.
Ord k2 =>
(a -> a -> a) -> (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeysWith forall a. Ord a => Set a -> Set a -> Set a
Set.union a -> c
f Map a (Set b)
ab
dc :: Map d (Set c)
dc = forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (forall b a. Ord b => (a -> b) -> Set a -> Set b
Set.map a -> c
f) forall a b. (a -> b) -> a -> b
$ forall k2 a k1.
Ord k2 =>
(a -> a -> a) -> (k1 -> k2) -> Map k1 a -> Map k2 a
Map.mapKeysWith forall a. Ord a => Set a -> Set a -> Set a
Set.union b -> d
g Map b (Set a)
ba
mesh :: (Ord a, Ord b) => [a] -> [b] -> AdjacencyMap (a, b) (a, b)
mesh :: forall a b.
(Ord a, Ord b) =>
[a] -> [b] -> AdjacencyMap (a, b) (a, b)
mesh [a]
as [b]
bs = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a a -> AdjacencyMap b b -> AdjacencyMap (a, b) (a, b)
box (forall a b. (Ord a, Ord b) => List a b -> AdjacencyMap a b
path forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [a]
as) (forall a b. (Ord a, Ord b) => List a b -> AdjacencyMap a b
path forall a b. (a -> b) -> a -> b
$ forall l. IsList l => [Item l] -> l
fromList [b]
bs)
box :: (Ord a, Ord b) => AdjacencyMap a a -> AdjacencyMap b b -> AdjacencyMap (a, b) (a, b)
box :: forall a b.
(Ord a, Ord b) =>
AdjacencyMap a a -> AdjacencyMap b b -> AdjacencyMap (a, b) (a, b)
box = forall a b c d e f.
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) =>
(a -> c -> e)
-> (b -> d -> e)
-> (a -> d -> f)
-> (b -> c -> f)
-> AdjacencyMap a b
-> AdjacencyMap c d
-> AdjacencyMap e f
boxWith (,) (,) (,) (,)
boxWith :: (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f)
=> (a -> c -> e) -> (b -> d -> e) -> (a -> d -> f) -> (b -> c -> f)
-> AdjacencyMap a b -> AdjacencyMap c d -> AdjacencyMap e f
boxWith :: forall a b c d e f.
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) =>
(a -> c -> e)
-> (b -> d -> e)
-> (a -> d -> f)
-> (b -> c -> f)
-> AdjacencyMap a b
-> AdjacencyMap c d
-> AdjacencyMap e f
boxWith a -> c -> e
ac b -> d -> e
bd a -> d -> f
ad b -> c -> f
bc AdjacencyMap a b
x AdjacencyMap c d
y = forall a b.
(Ord a, Ord b) =>
AdjacencyMap (Either a b) -> AdjacencyMap a b
toBipartite (forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap (Either a b, Either c d) -> Either e f
combine AdjacencyMap (Either a b, Either c d)
ambox)
where
ambox :: AdjacencyMap (Either a b, Either c d)
ambox = forall a b.
(Ord a, Ord b) =>
AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
AM.box (forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap (Either a b)
fromBipartite AdjacencyMap a b
x) (forall a b.
(Ord a, Ord b) =>
AdjacencyMap a b -> AdjacencyMap (Either a b)
fromBipartite AdjacencyMap c d
y)
combine :: (Either a b, Either c d) -> Either e f
combine (Left a
a, Left c
c) = forall a b. a -> Either a b
Left (a -> c -> e
ac a
a c
c)
combine (Left a
a, Right d
d) = forall a b. b -> Either a b
Right (a -> d -> f
ad a
a d
d)
combine (Right b
b, Left c
c) = forall a b. b -> Either a b
Right (b -> c -> f
bc b
b c
c)
combine (Right b
b, Right d
d) = forall a b. a -> Either a b
Left (b -> d -> e
bd b
b d
d)
consistent :: (Ord a, Ord b) => AdjacencyMap a b -> Bool
consistent :: forall a b. (Ord a, Ord b) => AdjacencyMap a b -> Bool
consistent (BAM Map a (Set b)
lr Map b (Set a)
rl) = forall {a} {b}. Map a (Set b) -> [(a, b)]
edgeList Map a (Set b)
lr forall a. Eq a => a -> a -> Bool
== forall a. Ord a => [a] -> [a]
sort (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> (b, a)
Data.Tuple.swap forall a b. (a -> b) -> a -> b
$ forall {a} {b}. Map a (Set b) -> [(a, b)]
edgeList Map b (Set a)
rl)
where
edgeList :: Map a (Set b) -> [(a, b)]
edgeList Map a (Set b)
lr = [ (a
u, b
v) | (a
u, Set b
vs) <- forall k a. Map k a -> [(k, a)]
Map.toAscList Map a (Set b)
lr, b
v <- forall a. Set a -> [a]
Set.toAscList Set b
vs ]