-- Generate.hs

module Graphter.Generate where
import Graphter.Representation
import Data.List

--
-- Generate complete graph
--

completeGraph :: Type -> Int -> Graph
completeGraph graphType vertexCount = Graph graphType vertices
    [uncurry Edge edge 0 | edge <-
        if (==) graphType Directed
        then edges
        else removeDuplicates edges]
    where
        vertices = [Vertex (show name) 0 | name <- [1..vertexCount]]
        edges = [(from, to) | from <- vertices, to <- vertices, (/=) from to]
        tupleEq (x, y) (u, v) = ((==) x u && (==) y v) || ((==) x v && (==) y u)
        removeDuplicates = nubBy tupleEq

--
-- Generate complete bipartite graph
--

completeBipartiteGraph :: Type -> Int -> Int -> Graph
completeBipartiteGraph _ 0 _ = error "Partite set cannot contains 0 vertices."
completeBipartiteGraph _ _ 0 = error "Partite set cannot contains 0 vertices."
completeBipartiteGraph kind x y = Graph kind ((++) verticesSet1 verticesSet2) edges
    where
        verticesSet1 = [Vertex (show name) 0 | name <- [1..x]]
        verticesSet2 = [Vertex (show name) 0 | name <- [((+) x 1)..((+) y x)]]
        edges = if (==) kind Directed
                then (++) [Edge from to 0
                    | from <- verticesSet1, to <- verticesSet2]
                    [Edge from to 0 | from <- verticesSet2, to <- verticesSet1]
                else [Edge from to 0 | from <- verticesSet1, to <- verticesSet2]
