module Data.Graph.UGraph.DegreeSequence
(
DegreeSequence
, degreeSequence
, getDegreeSequence
, isGraphicalSequence
, holdsHandshakingLemma
) where
import Data.List (reverse, sort)
import Data.Hashable
import Data.Graph.Types
import Data.Graph.UGraph
newtype DegreeSequence = DegreeSequence { unDegreeSequence :: [Int]}
deriving (Eq, Ord, Show)
degreeSequence :: [Int] -> DegreeSequence
degreeSequence = DegreeSequence . reverse . sort . filter (>0)
getDegreeSequence :: (Hashable v, Eq v) => UGraph v e -> Maybe DegreeSequence
getDegreeSequence g
| (not . isSimple) g = Nothing
| otherwise = Just $ degreeSequence $ degrees g
isGraphicalSequence :: DegreeSequence -> Bool
isGraphicalSequence (DegreeSequence []) = True
isGraphicalSequence (DegreeSequence (x:xs))
| x > length xs = False
| otherwise = isGraphicalSequence $ degreeSequence seq'
where seq' = subtract 1 <$> take x xs ++ drop x xs
isDirectedGraphic :: DegreeSequence -> Bool
isDirectedGraphic = undefined
holdsHandshakingLemma :: DegreeSequence -> Bool
holdsHandshakingLemma = even . length . filter odd . unDegreeSequence
fromGraphicalSequence :: DegreeSequence -> Maybe (UGraph Int ())
fromGraphicalSequence = undefined