-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A utility for computing distributions of material to review among reviewers.
--
-- A utility for computing distributions of material to review among
-- reviewers. Referees takes into consideration the areas of
-- expertise of the referees, the number of items that they accept for
-- review, the languages they understand, and the minimum and maximum
-- number of copies we may want to distribute per each item to review.
@package Referees
@version 0.0.0
-- | Types and constructors for use in Referees.Solver.
module Referees.Solver.Types.Internal
-- | 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 Matrixs and [] having taken place
-- in their construction.
newtype Index a
Index :: Int -> Index a
_idx :: Index a -> Int
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 -> b -> Maybe c -> Profit
data Bounds a
Bounds :: a -> a -> Bounds a
_lower :: Bounds a -> a
_upper :: Bounds a -> a
-- | 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 -> a -> Maybe (Bounds a)
instance Show (Index a)
instance Read (Index a)
instance Eq (Index a)
instance Num (Index a)
instance Enum (Index a)
instance Eq a => Eq (Bounds a)
instance Show a => Show (Bounds a)
-- | This module contains the core functions used in solving the
-- Generalized Assignment Problem with the help of the GLPK toolkit.
module Referees.Solver.Internal
-- | lpGAP is based on Martello & Toth 1990’s linear integer
-- programming formulation of the Generalized Assignment Problem (GAP).
-- This function, in addition, excludes all combinations whose profit is
-- 0. lpGAP interfaces with the GLPK toolkit
-- through glpk-hs.
--
-- In lpGAP profitM caps bounds, profitM is a
-- profit matrix (which can be computed by mkProfitMatrix, using a
-- ProfitFunction), caps stands for a list of items’
-- capacities (computable by toCap), and bounds encodes
-- in a Bounds Copies value (producible with
-- mkBounds) both the lower and upper bounds on the number of
-- copies to distribute per each item.
--
--
-- - Cf. Martello, S. and Toth, P.: Knapsack Problems: Algorithms
-- and Computer Implementations, ch. 7, John Wiley & Sons,
-- 1990.
--
lpGAP :: ProfitMatrix -> [Capacity] -> Bounds Copies -> LP String Double
-- | x i j, for i = {1, …, m}, j = {1, …,
-- n}, where m stands for the number of items, and
-- n for the number of bins. These “variables” are to be used
-- only within the GAP formulation in lpGAP.
x :: Row -> Col -> String
-- | Objective function to maximize in lpGAP. It stands for the
-- overall profit accrued by a given distribution of items among bins.
--
--
-- - Cf. Martello, S. and Toth, P.: op. cit.
--
objFun :: ProfitMatrix -> LinFunc String Double
-- | Constraint function. It is used, in lpGAP, to specify the
-- capacity of each bin. Note that items are not divisible, and therefore
-- their cost, as detracted from a given bin’s capacity, is fixed at
-- 1.
--
--
-- - Cf. Martello, S. and Toth, P.: op. cit.
--
subFunCap :: ProfitMatrix -> Col -> LinFunc String Double
-- | Constraint function. It is used, in lpGAP, to specify how many
-- copies of each item can be distributed.
--
--
-- - Cf. Martello, S. and Toth, P.: op. cit.
--
subFunMult :: ProfitMatrix -> Row -> LinFunc String Double
-- | Given a ProfitFunction, mkProfitMatrix computes a profit
-- matrix between bins and items, optionally taking a
-- quality as being by default shared between them. The values
-- in a ProfitMatrix serve to distribute items among bins
-- according to the capacities of the latter and the values of the
-- former.
mkProfitMatrix :: ProfitFunction a b c -> [a] -> [b] -> Maybe c -> ProfitMatrix
-- | Wrapper to use matrix with extra type safety.
safeMatrix :: Row -> Col -> ((Row, Col) -> Double) -> ProfitMatrix
-- | Wrapper to use getElem with extra type safety.
safeGetElem :: ProfitMatrix -> (Row, Col) -> Double
-- | Simple helper function to run the glpk-hs interface to GLPK,
-- as constructed with lpGAP. Takes the same arguments as
-- lpGAP.
run_lpGAP :: ProfitMatrix -> [Capacity] -> Bounds Copies -> IO (ReturnCode, Maybe (Double, Map String Double))
-- | fromGLPKtoList turns the (unIOd) output of run_lpGAP
-- into a more usable format.
fromGLPKtoList :: (ReturnCode, Maybe (Double, Map String Double)) -> Maybe [(Col, Row)]
-- | This module reexports some types and functions from
-- Referees.Solver.Types.Internal.
module Referees.Solver.Types
-- | 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 Matrixs and [] having taken place
-- in their construction.
newtype Index a
Index :: Int -> Index a
_idx :: Index a -> Int
type Row = Index Row'
type Col = Index Col'
type ProfitFunction a b c = a -> b -> Maybe c -> Profit
type ProfitMatrix = Matrix Profit
data Bounds a
-- | 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 -> a -> Maybe (Bounds a)
-- | Represents the capacity of some bin.
type Capacity = Int
-- | Represents the number of copies to make of some item.
type Copies = Int
-- | Types and constructors for use in Referees.
module Referees.Types.Internal
type Name = String
type Language = String
type Area = String
type Subarea = String
data Entry subtype
Entry :: Name -> Maybe Capacity -> [Language] -> [(Area, [Subarea])] -> Entry subtype
_name :: Entry subtype -> Name
_capacity :: Entry subtype -> Maybe Capacity
_languages :: Entry subtype -> [Language]
_areas :: Entry subtype -> [(Area, [Subarea])]
data Referee
Referee :: Referee
data Proposal
Proposal :: Proposal
type Match = (Entry Referee, [Entry Proposal])
-- | For warning about issues that may take place during parsing.
data CSV_Warning
DifferingCapacities :: Name -> CSV_Warning
newtype StringListParse sep
StrLstP :: [String] -> StringListParse sep
_strLstP :: StringListParse sep -> [String]
data Semicolon
Semicolon :: Semicolon
newtype MaybeCapacityParse
MaybeCapP :: Maybe Capacity -> MaybeCapacityParse
_maybeCapP :: MaybeCapacityParse -> Maybe Capacity
-- | This type and its FromField instance declarations are used to
-- describe the parsing rules for reconstruction of Entry values
-- from CSV files.
--
-- The two FromField instance declarations here (vid. source)
-- enable silent conditional parsing of the second field in a CSV file
-- with 4 fields. In this scenario, if the second field is parseable as
-- Int, it is parsed as MaybeCapacityParse (a wrapper for
-- Maybe Capacity); otherwise, as StringListParse
-- Semicolon (a wrapper for [String]).
data CSVentry
CSVentry :: !Name -> !MaybeCapacityParse -> !(StringListParse Semicolon) -> !Area -> !(StringListParse Semicolon) -> CSVentry
_nameCSV :: CSVentry -> !Name
_capacityCSV :: CSVentry -> !MaybeCapacityParse
_languagesCSV :: CSVentry -> !(StringListParse Semicolon)
_areaCSV :: CSVentry -> !Area
_subareasCSV :: CSVentry -> !(StringListParse Semicolon)
instance Eq (Entry subtype)
instance Show (Entry subtype)
instance Eq (StringListParse sep)
instance Show (StringListParse sep)
instance Eq MaybeCapacityParse
instance Show MaybeCapacityParse
instance FromRecord CSVentry
instance FromField MaybeCapacityParse
instance FromField (StringListParse Semicolon)
-- | This module reexports some functions from
-- Referees.Solver.Internal.
module Referees.Solver
-- | Given a ProfitFunction, mkProfitMatrix computes a profit
-- matrix between bins and items, optionally taking a
-- quality as being by default shared between them. The values
-- in a ProfitMatrix serve to distribute items among bins
-- according to the capacities of the latter and the values of the
-- former.
mkProfitMatrix :: ProfitFunction a b c -> [a] -> [b] -> Maybe c -> ProfitMatrix
-- | Simple helper function to run the glpk-hs interface to GLPK,
-- as constructed with lpGAP. Takes the same arguments as
-- lpGAP.
run_lpGAP :: ProfitMatrix -> [Capacity] -> Bounds Copies -> IO (ReturnCode, Maybe (Double, Map String Double))
-- | fromGLPKtoList turns the (unIOd) output of run_lpGAP
-- into a more usable format.
fromGLPKtoList :: (ReturnCode, Maybe (Double, Map String Double)) -> Maybe [(Col, Row)]
-- | This module defines the functions needed to specialize
-- Referees.Solver to the problem of assigning proposals among
-- referees.
module Referees.Internal
-- | Parses from a CSV file into Entry Referee values.
fromCSVtoReferees :: FilePath -> IO [Entry Referee]
-- | Parses from a CSV file into Entry Proposal values.
fromCSVtoProposals :: FilePath -> IO [Entry Proposal]
-- | Taking the path to some CSV file in the appropriate format, parses it
-- into values of type Entry a. This function is intended
-- to be used with wrappers that specialize a to some concrete
-- type.
fromCSVtoEntry :: FilePath -> IO [Entry a]
-- | Parses CSV files into CSVentrys, according to the format
-- described in Referees.
--
-- The parser is defined at the FromField instance declarations
-- in Referees.Types.Internal.
readCSVentries :: FilePath -> IO [CSVentry]
-- | distributeWith computes a distribution of proposals among
-- referees, according to the given parameters.
distributeWith :: ProfitFunction (Entry Proposal) (Entry Referee) Language -> [Entry Referee] -> Capacity -> Bounds Copies -> Maybe Language -> [Entry Proposal] -> IO (Maybe [Match])
-- | Computes the profit for an assignment between the given Entry
-- Proposal and Entry Referee. The scale is
-- continuous in [0,2]. Takes understood languages into account.
profitRefProp :: ProfitFunction (Entry Proposal) (Entry Referee) Language
-- | This list is used to bias the profit associated with Areas
-- and Subareas matches according to their order in the
-- corresponding Entrys.
logBias :: [Double]
-- | toCap rs def builds a list of capacities matching the
-- Referees in rs, while assigning default capacity
-- def to those Referees that don’t have one defined.
toCap :: [Entry Referee] -> Capacity -> [Capacity]
-- | Provides a list of all Referees suited for a Proposal,
-- regardless of any distribution.
whichRefereesForProposal :: Entry Proposal -> [Entry Referee] -> Maybe Language -> [Entry Referee]
-- | Provides a list of all Proposals suited for a Referee,
-- regardless of any distribution.
whichProposalsForReferee :: Entry Referee -> [Entry Proposal] -> Maybe Language -> [Entry Proposal]
-- | Concise printing of assignments. Ignores Entry Referees
-- for which there are no assigned Entry Proposals.
ppDistribution :: Maybe [Match] -> String
ppReferee :: Entry Referee -> String
ppProposal :: Entry Proposal -> String
ppEntry :: Entry a -> String
-- | Pretty prints the given matrix, converting its values to 2-digit
-- precision. This is currently used only in debug.
ppMatrix :: Matrix Double -> String
ppCSV_Warning :: CSV_Warning -> String
ppNames :: [Name] -> String
-- | 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 -> a -> Maybe (Bounds a)
-- | This module reexports some types and functions from
-- Referees.Types.Internal.
module Referees.Types
type Name = String
type Language = String
type Area = String
type Subarea = String
data Entry subtype
Entry :: Name -> Maybe Capacity -> [Language] -> [(Area, [Subarea])] -> Entry subtype
_name :: Entry subtype -> Name
_capacity :: Entry subtype -> Maybe Capacity
_languages :: Entry subtype -> [Language]
_areas :: Entry subtype -> [(Area, [Subarea])]
data Referee
data Proposal
type Match = (Entry Referee, [Entry Proposal])
-- | Utility for computing distributions of material to review among
-- reviewers.
--
-- Example of use:
--
--
-- - First, load the CSV files representing referees and
-- proposals:
--
--
--
-- >>> referees <- fromCSVtoReferees "referees.csv"
--
-- >>> proposals <- fromCSVtoProposals "proposals.csv"
--
--
-- Each line in these files obeys the following format:
--
--
-- Name,Capacity,Language;…;Language,Area,Subarea;…;Subarea
--
--
-- Area and Subarea fields can be empty but they must be
-- present. Capacity and Language fields are optional. If
-- only one of them is included, the parser will detect which one on the
-- basis of whether it contains digits.
--
-- If there are many areas (and corresponding subareas) for some
-- Name, these go in different lines, as in the following example:
--
--
-- RefereeA,3,Spanish,Metaphysics,Identity
-- RefereeA,Greek,Aesthetics
-- RefereeB,1,PoliticalPhilosophy,State;Justice
-- RefereeC,Catalan,PhilosophyOfMind,Perception
--
--
--
-- - Then, use the distributeWith function; the
-- ProfitFunction used in the example is provided by the
-- library:
--
--
--
-- >>> let Just bnds = mkBounds 1 3
--
-- >>> match <- distributeWith profitRefProp referees 3 bnds (Just "Greek") proposals
--
--
-- Now you can pretty print the outcome:
--
--
-- >>> putStr $ ppDistribution match
--
module Referees
-- | Parses from a CSV file into Entry Referee values.
fromCSVtoReferees :: FilePath -> IO [Entry Referee]
-- | Parses from a CSV file into Entry Proposal values.
fromCSVtoProposals :: FilePath -> IO [Entry Proposal]
-- | distributeWith computes a distribution of proposals among
-- referees, according to the given parameters.
distributeWith :: ProfitFunction (Entry Proposal) (Entry Referee) Language -> [Entry Referee] -> Capacity -> Bounds Copies -> Maybe Language -> [Entry Proposal] -> IO (Maybe [Match])
-- | Computes the profit for an assignment between the given Entry
-- Proposal and Entry Referee. The scale is
-- continuous in [0,2]. Takes understood languages into account.
profitRefProp :: ProfitFunction (Entry Proposal) (Entry Referee) Language
-- | 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 -> a -> Maybe (Bounds a)
-- | Provides a list of all Referees suited for a Proposal,
-- regardless of any distribution.
whichRefereesForProposal :: Entry Proposal -> [Entry Referee] -> Maybe Language -> [Entry Referee]
-- | Provides a list of all Proposals suited for a Referee,
-- regardless of any distribution.
whichProposalsForReferee :: Entry Referee -> [Entry Proposal] -> Maybe Language -> [Entry Proposal]
-- | Concise printing of assignments. Ignores Entry Referees
-- for which there are no assigned Entry Proposals.
ppDistribution :: Maybe [Match] -> String