
module Igor2.Data.Rateable (

    Rateable(..), RatingData, ratingData, emptyRatingData
    
    )where

import Igor2.Data.CallDependencies
import Igor2.Data.IOData

import Syntax
import Igor2.Logging
import Igor2.Ppr

import Control.Monad.Error
import Data.List
import Data.Function (on)
import qualified Data.Map as M
import qualified Data.MySet as S

{-
    RatingData seems to be used only in the class Rateable, which only instance
    is Hypo from src/Igor2/Data/Hypotheses.hs. heur_rating is an heuristic
    rating. The list of floats contains the (average) number of rules per
    function as well as the (average) number of rules per partition. Other
    values might be added to it, like the number of cycles per function and the
    number of loops per function (see the function "heuristic" in
    Hypotheses.hs). The second tuple entry is the arithmetic mean of the values
    in the list.
    According to a comment for "heuristic", heur_rating is used for
    visualisation only.
-}
data RatingData = RD { partitions :: Int
                     , openRules :: Int
                     , totalRules :: Int
                     , freeVars :: Int
                     , heur_rating :: ([Float], Float) }
                deriving (Eq, Show)

instance Ord RatingData where
    compare = compare `on` \(RD a b c d _) -> (a, b, c, d)

instance Pretty RatingData where
        pretty r = tupled $ [int (partitions r) <> text " partitions",
                             int (openRules r) <> text " / " <> int (totalRules r) <> text " rules open",
                             int (freeVars r) <> text " vars free",
                             pretty (heur_rating r)]

ratingData = RD

emptyRatingData = ratingData (-1)(-1)(-1)(-1)([],(0/0))        

        
class Rateable r where
    rate :: (Monad m) => r -> C m RatingData
--------------------------------------------------------------------------------
-- Rate a Rule
--------------------------------------------------------------------------------
--instance Rateable Rule where
--    rate r =  size (lhs r) * size (rhs r)

--------------------------------------------------------------------------------
-- Rate a CovrRulement
--------------------------------------------------------------------------------
--instance Rateable CovrRule where
--    rate = rate.crul


                     