module Math.FiniteCategories.SafeCompositionGraph.Examples
(
exampleSafeCompositionGraph,
exampleLoopingSafeCompositionGraph,
exampleScgString,
exampleRandomSafeCompositionGraph,
)
where
import qualified Data.WeakSet as Set
import Data.WeakSet.Safe
import Data.WeakMap.Safe
import Math.FiniteCategory
import Math.Categories
import Math.FiniteCategories
import Data.Text (Text)
import System.Random
exampleSafeCompositionGraph :: SafeCompositionGraph Int Char
exampleSafeCompositionGraph :: SafeCompositionGraph Int Char
exampleSafeCompositionGraph = SafeCompositionGraph Int Char
result
where
Right SafeCompositionGraph Int Char
result = Graph Int Char
-> CompositionLaw Int Char
-> Int
-> Either
(FiniteCategoryError (SCGMorphism Int Char) Int)
(SafeCompositionGraph Int Char)
forall a b.
(Eq a, Eq b) =>
Graph a b
-> CompositionLaw a b
-> Int
-> Either
(FiniteCategoryError (SCGMorphism a b) a)
(SafeCompositionGraph a b)
safeCompositionGraph Graph Int Char
underlyingGraph CompositionLaw Int Char
compositionLaw Int
3
Just Graph Int Char
underlyingGraph = Set Int -> Set (Arrow Int Char) -> Maybe (Graph Int Char)
forall n e. Eq n => Set n -> Set (Arrow n e) -> Maybe (Graph n e)
graph ([Int] -> Set Int
forall a. [a] -> Set a
set [Int
1 :: Int,Int
2,Int
3]) ([Arrow Int Char] -> Set (Arrow Int Char)
forall a. [a] -> Set a
set [Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
1,labelArrow :: Char
labelArrow=Char
'a'},Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
2,labelArrow :: Char
labelArrow=Char
'b'},Arrow{sourceArrow :: Int
sourceArrow=Int
2,targetArrow :: Int
targetArrow=Int
3,labelArrow :: Char
labelArrow=Char
'c'}])
compositionLaw :: CompositionLaw Int Char
compositionLaw = AssociationList [Arrow Int Char] [Arrow Int Char]
-> CompositionLaw Int Char
forall k v. AssociationList k v -> Map k v
weakMap [([Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
1,labelArrow :: Char
labelArrow=Char
'a'},Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
1,labelArrow :: Char
labelArrow=Char
'a'}],[Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
1,labelArrow :: Char
labelArrow=Char
'a'}])]
exampleLoopingSafeCompositionGraph :: SafeCompositionGraph Int Char
exampleLoopingSafeCompositionGraph :: SafeCompositionGraph Int Char
exampleLoopingSafeCompositionGraph = SafeCompositionGraph Int Char
result
where
Right SafeCompositionGraph Int Char
result = Graph Int Char
-> CompositionLaw Int Char
-> Int
-> Either
(FiniteCategoryError (SCGMorphism Int Char) Int)
(SafeCompositionGraph Int Char)
forall a b.
(Eq a, Eq b) =>
Graph a b
-> CompositionLaw a b
-> Int
-> Either
(FiniteCategoryError (SCGMorphism a b) a)
(SafeCompositionGraph a b)
safeCompositionGraph (Set Int -> Set (Arrow Int Char) -> Graph Int Char
forall n e. Set n -> Set (Arrow n e) -> Graph n e
unsafeGraph ([Int] -> Set Int
forall a. [a] -> Set a
set [Int
1 :: Int]) ([Arrow Int Char] -> Set (Arrow Int Char)
forall a. [a] -> Set a
set [Arrow{sourceArrow :: Int
sourceArrow=Int
1,targetArrow :: Int
targetArrow=Int
1,labelArrow :: Char
labelArrow=Char
'a'}])) (AssociationList [Arrow Int Char] [Arrow Int Char]
-> CompositionLaw Int Char
forall k v. AssociationList k v -> Map k v
weakMap []) Int
3
exampleScgString :: SafeCompositionGraph Text Text
Right SafeCompositionGraph Text Text
exampleScgString = String
-> Either
(FiniteCategoryError (SCGMorphism Text Text) Text)
(SafeCompositionGraph Text Text)
readSCGString String
"2\nA -f-> B -g-> C = A -h-> C"
exampleRandomSafeCompositionGraph :: SafeCompositionGraph Int Int
exampleRandomSafeCompositionGraph :: SafeCompositionGraph Int Int
exampleRandomSafeCompositionGraph = SafeCompositionGraph Int Int
result
where
randomGen :: StdGen
randomGen = Int -> StdGen
mkStdGen Int
123456
(SafeCompositionGraph Int Int
result,StdGen
newGen) = StdGen -> (SafeCompositionGraph Int Int, StdGen)
forall g. RandomGen g => g -> (SafeCompositionGraph Int Int, g)
defaultConstructRandomSafeCompositionGraph StdGen
randomGen