{- |
Module : Referees.Solver.Types.Internal
Copyright : (c) Pablo Couto 2014
License : GPL-3
Maintainer : pablo@infty.in
Stability : experimental

Types and constructors for use in "Referees.Solver".-}

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Referees.Solver.Types.Internal where

import Data.Matrix ( Matrix )

-- | Represents the capacity of some bin.
--
type Capacity = Int

-- | Represents the number of copies to make of some item.
--
type Copies = Int

-- | Note that values of this type, when used to represent indices for a
-- 'Matrix', may not be directly usable with access functions from
-- "Data.Matrix". This is due to the possibility of some conversion between
-- indices for 'Matrix's and @[]@ having taken place in their construction.
--
newtype Index a = Index
        { _idx :: Int
        } deriving (Show, Read, Eq, Num, Enum)

type Row = Index Row'  ; data Row'
type Col = Index Col'  ; data Col'

type Profit = Double
type ProfitMatrix = Matrix Profit

type ProfitFunction a b c = a -- ^ Some item
                          -> b -- ^ Some bin
                          -> Maybe c -- ^ An optional quality
                          -> Profit

data Bounds a = Bounds
     { _lower :: a
     , _upper :: a
     } deriving (Eq, Show)

-- | This function creates a ('Maybe') 'Bounds' value, holding both lower and
-- upper bounds for an interval, after verifying that they are consistent.
--
mkBounds :: (Num a, Ord a) => a -- ^ Lower bound
         -> a -- ^ Upper bound
         -> Maybe (Bounds a)
mkBounds i j =
  if i <= j
     then Just $ Bounds i j
     else Nothing