data Edge v = Edge {source :: v, target :: v}
deriving (Show,Eq,Ord)
data Graph v = Graph {nodes :: Set v, edges :: Set (Edge v)}
deriving Show
instance Arbitrary v => Arbitrary (Edge v) where
arbitrary = do s <- arbitrary
t <- arbitrary
return $ Edge {source = s, target = t}
instance (Ord v, Arbitrary v) => Arbitrary (Graph v) where
arbitrary = aux `suchThat` validGraph
where aux = do lNodes <- arbitrary
lEdges <- arbitrary
return $ Graph {nodes = fromList lNodes, edges = fromList lEdges}
I currently have this to generate my Graphs. However by using sample on ghci I noticed that it either doesn't generate edges or it generates a single one. Is it possible to control the number of edges generated? How would I do it?
EDIT: A Graph is considered valid when: 1-The source and target nodes of an edge exist. 2-A node can't be the source to more than one Edge.