{- |
   Module      : Main
   Description : Executable for dangd.
   Copyright   : (c) Ivan Lazar Miljenovic
   License     : 3-Clause BSD-style
   Maintainer  : Ivan.Miljenovic@gmail.com
 -}
module Main where

import Math.Combinatorics.Graph.Planar.DangD(generateDangDs, numB, numW)
import Math.Combinatorics.Graph.Planar.DangD.GF(mobileCounts, numMobiles, numDangDs)
import Data.Graph.Planar.Serialisation(encodePlanarFileFrom)
import Data.Graph.Planar.Serialisation.PlanarCode(PlanarCode(..))

import Control.Arrow(first)
import System.Environment(getArgs)

-- -----------------------------------------------------------------------------

main :: IO ()
main = do [d,n] <- getArgs
          let d' = read d
              n' = read n
              sgf = mobileCounts d' n'
              fp = "dangd" ++ d ++ "." ++ n
              desc = d ++ "-angulations of girth " ++ d
          case numB d' n' of
            Nothing -> putStrLn $ "There are no " ++ desc
                                   ++ " with " ++ n ++ " vertices."
            (Just b) ->
              do putStr "Number of internal faces: "
                 print b
                 putStr "Number of internal nodes: "
                 print $ numW d' n'
                 putStr "Expected mobiles: "
                 print $ numMobiles sgf
                 putStr "Expected dangds: "
                 print $ numDangDs sgf
                 putStr "Actual: "
                 c <- encodePlanarFileFrom PlanarCode fp
                      . map (first Just)
                      $ generateDangDs d' n'
                 putStrLn $ show c ++ " " ++ desc ++ " written to " ++ fp
