{-# LANGUAGE CPP, FlexibleContexts, UndecidableInstances #-}
module WeekDaze.ExecutionConfiguration.LessonCriteriaWeights(
LessonCriteriaWeights(..),
associationList,
tag,
weightOfAreResourcesReusedTag,
weightOfGreatestMinimumConsecutiveLessonsTag,
weightOfGreatestRemainingCourseLessonsTag,
weightOfGreatestSynchronisedCourseSetSizeTag,
weightOfIsCoreKnowledgeRequirementTag,
weightOfIsSpecialistInTopicTag,
weightOfMatchCourseClassSizeToLocationCapacityTag,
weightOfMaximiseRelativeFacilityUtilisationTag,
weightOfMaximiseStudentClassSizeOverCourseClassSizeTag,
weightOfMaximiseStudentClassSizeOverLocationCapacityTag,
weightOfMinimiseBookingAtAnotherCoursesSpecifiedTimeTag,
weightOfMinimiseBookingOfLocationByOtherTeachersTag,
weightOfMinimiseDeviationFromTimeslotRequestTag,
weightOfMinimiseInterCampusMigrationsOfStudentsTag,
weightOfMinimiseInterCampusMigrationsOfTeachersTag,
weightOfMinimiseStudentBodyCombinationsTag,
weightOfMinimiseTeachersLocusOperandiTag,
weightOfMinimiseWasteOfScarceFacilitiesTag,
calculateWeightedMean,
perturbWeights,
zeroWeightOfGreatestMinimumConsecutiveLessons,
zeroWeightOfGreatestSynchronisedCourseSetSize,
zeroWeightOfIsCoreKnowledgeRequirement,
zeroWeightOfIsSpecialistInTopic,
zeroWeightOfMatchCourseClassSizeToLocationCapacity,
zeroWeightOfMaximiseRelativeFacilityUtilisation,
zeroWeightOfMaximiseStudentClassSizeOverCourseClassSize,
zeroWeightOfMaximiseStudentClassSizeOverLocationCapacity,
zeroWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
zeroWeightOfMinimiseBookingOfLocationByOtherTeachers,
zeroWeightOfMinimiseDeviationFromTimeslotRequest,
zeroWeightOfMinimiseInterCampusMigrationsOfStudents,
zeroWeightOfMinimiseInterCampusMigrationsOfTeachers,
zeroWeightOfMinimiseTeachersLocusOperandi,
zeroWeightOfMinimiseWasteOfScarceFacilities
) where
import qualified Control.DeepSeq
import qualified Control.Monad.Writer
import qualified Data.Default
import qualified System.Random
import qualified Text.XML.HXT.Arrow.Pickle as HXT
import qualified ToolShed.SelfValidate
import qualified WeekDaze.ExecutionConfiguration.Criterion as ExecutionConfiguration.Criterion
import qualified WeekDaze.ExecutionConfiguration.CriterionWeight as ExecutionConfiguration.CriterionWeight
import qualified WeekDaze.ExecutionConfiguration.OptimiseLessonCriteriaWeights as ExecutionConfiguration.OptimiseLessonCriteriaWeights
#ifdef USE_HDBC
import qualified Database.HDBC
import qualified Data.Convertible
import qualified Data.Maybe
import qualified Data.Typeable
import qualified WeekDaze.Database.Selector as Database.Selector
instance (
Data.Convertible.Convertible Database.HDBC.SqlValue w,
Data.Typeable.Typeable w,
RealFrac w
) => Database.Selector.Selector (LessonCriteriaWeights w) where
fromDatabase connection projectIdSql = let
tableName :: Database.Selector.TableName
tableName = Database.Selector.tablePrefix ++ tag
in do
criterionWeightRows <- map (
map $ Data.Maybe.fromMaybe Data.Default.def . either (
error . showString "WeekDaze.ExecutionConfiguration.LessonCriteriaWeights.fromDatabase:\tfailed to parse the value of a weight read from the database; " . show
) id . Database.HDBC.safeFromSql
) `fmap` Database.Selector.select connection (
map fst associationList
) [tableName] [(Database.Selector.projectIdColumnName, projectIdSql)]
return $ case criterionWeightRows of
[] -> Data.Default.def
[weightRow] -> case weightRow of
[
weightOfAreResourcesReused,
weightOfGreatestMinimumConsecutiveLessons,
weightOfGreatestRemainingCourseLessons,
weightOfGreatestSynchronisedCourseSetSize,
weightOfIsCoreKnowledgeRequirement,
weightOfIsSpecialistInTopic,
weightOfMatchCourseClassSizeToLocationCapacity,
weightOfMaximiseRelativeFacilityUtilisation,
weightOfMaximiseStudentClassSizeOverCourseClassSize,
weightOfMaximiseStudentClassSizeOverLocationCapacity,
weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
weightOfMinimiseBookingOfLocationByOtherTeachers,
weightOfMinimiseDeviationFromTimeslotRequest,
weightOfMinimiseInterCampusMigrationsOfStudents,
weightOfMinimiseInterCampusMigrationsOfTeachers,
weightOfMinimiseStudentBodyCombinations,
weightOfMinimiseTeachersLocusOperandi,
weightOfMinimiseWasteOfScarceFacilities
] -> MkLessonCriteriaWeights {
getWeightOfAreResourcesReused = weightOfAreResourcesReused,
getWeightOfGreatestMinimumConsecutiveLessons = weightOfGreatestMinimumConsecutiveLessons,
getWeightOfGreatestRemainingCourseLessons = weightOfGreatestRemainingCourseLessons,
getWeightOfGreatestSynchronisedCourseSetSize = weightOfGreatestSynchronisedCourseSetSize,
getWeightOfIsCoreKnowledgeRequirement = weightOfIsCoreKnowledgeRequirement,
getWeightOfIsSpecialistInTopic = weightOfIsSpecialistInTopic,
getWeightOfMatchCourseClassSizeToLocationCapacity = weightOfMatchCourseClassSizeToLocationCapacity,
getWeightOfMaximiseRelativeFacilityUtilisation = weightOfMaximiseRelativeFacilityUtilisation,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = weightOfMaximiseStudentClassSizeOverCourseClassSize,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = weightOfMaximiseStudentClassSizeOverLocationCapacity,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = weightOfMinimiseBookingOfLocationByOtherTeachers,
getWeightOfMinimiseDeviationFromTimeslotRequest = weightOfMinimiseDeviationFromTimeslotRequest,
getWeightOfMinimiseInterCampusMigrationsOfStudents = weightOfMinimiseInterCampusMigrationsOfStudents,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = weightOfMinimiseInterCampusMigrationsOfTeachers,
getWeightOfMinimiseStudentBodyCombinations = weightOfMinimiseStudentBodyCombinations,
getWeightOfMinimiseTeachersLocusOperandi = weightOfMinimiseTeachersLocusOperandi,
getWeightOfMinimiseWasteOfScarceFacilities = weightOfMinimiseWasteOfScarceFacilities
}
_ -> error $ "WeekDaze.ExecutionConfiguration.LessonCriteriaWeights.fromDatabase:\tunexpected number of columns=" ++ show (length weightRow) ++ " in row of table " ++ show tableName ++ "."
_ -> error $ "WeekDaze.ExecutionConfiguration.LessonCriteriaWeights.fromDatabase:\tunexpected number of rows=" ++ show (length criterionWeightRows) ++ " selected from table " ++ show tableName ++ "."
#endif /* USE_HDBC */
tag :: String
tag = "lessonCriteriaWeights"
weightOfAreResourcesReusedTag :: String
weightOfAreResourcesReusedTag = "areResourcesReused"
weightOfGreatestMinimumConsecutiveLessonsTag :: String
weightOfGreatestMinimumConsecutiveLessonsTag = "greatestMinimumConsecutiveLessons"
weightOfGreatestRemainingCourseLessonsTag :: String
weightOfGreatestRemainingCourseLessonsTag = "greatestRemainingCourseLessons"
weightOfGreatestSynchronisedCourseSetSizeTag :: String
weightOfGreatestSynchronisedCourseSetSizeTag = "greatestSynchronisedCourseSetSize"
weightOfIsCoreKnowledgeRequirementTag :: String
weightOfIsCoreKnowledgeRequirementTag = "isCoreKnowledgeRequirement"
weightOfIsSpecialistInTopicTag :: String
weightOfIsSpecialistInTopicTag = "isSpecialistInTopic"
weightOfMatchCourseClassSizeToLocationCapacityTag :: String
weightOfMatchCourseClassSizeToLocationCapacityTag = "matchCourseClassSizeToLocationCapacity"
weightOfMaximiseRelativeFacilityUtilisationTag :: String
weightOfMaximiseRelativeFacilityUtilisationTag = "maximiseRelativeFacilityUtilisation"
weightOfMaximiseStudentClassSizeOverCourseClassSizeTag :: String
weightOfMaximiseStudentClassSizeOverCourseClassSizeTag = "maximiseStudentClassSizeOverCourseClassSize"
weightOfMaximiseStudentClassSizeOverLocationCapacityTag :: String
weightOfMaximiseStudentClassSizeOverLocationCapacityTag = "maximiseStudentClassSizeOverLocationCapacity"
weightOfMinimiseBookingAtAnotherCoursesSpecifiedTimeTag :: String
weightOfMinimiseBookingAtAnotherCoursesSpecifiedTimeTag = "minimiseBookingAtAnotherCoursesSpecifiedTime"
weightOfMinimiseBookingOfLocationByOtherTeachersTag :: String
weightOfMinimiseBookingOfLocationByOtherTeachersTag = "minimiseBookingOfLocationByOtherTeachers"
weightOfMinimiseDeviationFromTimeslotRequestTag :: String
weightOfMinimiseDeviationFromTimeslotRequestTag = "minimiseDeviationFromTimeslotRequest"
weightOfMinimiseInterCampusMigrationsOfStudentsTag :: String
weightOfMinimiseInterCampusMigrationsOfStudentsTag = "minimiseInterCampusMigrationsOfStudents"
weightOfMinimiseInterCampusMigrationsOfTeachersTag :: String
weightOfMinimiseInterCampusMigrationsOfTeachersTag = "minimiseInterCampusMigrationsOfTeachers"
weightOfMinimiseStudentBodyCombinationsTag :: String
weightOfMinimiseStudentBodyCombinationsTag = "minimiseStudentBodyCombinations"
weightOfMinimiseTeachersLocusOperandiTag :: String
weightOfMinimiseTeachersLocusOperandiTag = "minimiseTeachersLocusOperandi"
weightOfMinimiseWasteOfScarceFacilitiesTag :: String
weightOfMinimiseWasteOfScarceFacilitiesTag = "minimiseWasteOfScarceFacilities"
associationList :: [(String, LessonCriteriaWeights w -> ExecutionConfiguration.CriterionWeight.CriterionWeight w)]
associationList = [
(weightOfAreResourcesReusedTag, getWeightOfAreResourcesReused),
(weightOfGreatestMinimumConsecutiveLessonsTag, getWeightOfGreatestMinimumConsecutiveLessons),
(weightOfGreatestRemainingCourseLessonsTag, getWeightOfGreatestRemainingCourseLessons),
(weightOfGreatestSynchronisedCourseSetSizeTag, getWeightOfGreatestSynchronisedCourseSetSize),
(weightOfIsCoreKnowledgeRequirementTag, getWeightOfIsCoreKnowledgeRequirement),
(weightOfIsSpecialistInTopicTag, getWeightOfIsSpecialistInTopic),
(weightOfMatchCourseClassSizeToLocationCapacityTag, getWeightOfMatchCourseClassSizeToLocationCapacity),
(weightOfMaximiseRelativeFacilityUtilisationTag, getWeightOfMaximiseRelativeFacilityUtilisation),
(weightOfMaximiseStudentClassSizeOverCourseClassSizeTag, getWeightOfMaximiseStudentClassSizeOverCourseClassSize),
(weightOfMaximiseStudentClassSizeOverLocationCapacityTag, getWeightOfMaximiseStudentClassSizeOverLocationCapacity),
(weightOfMinimiseBookingAtAnotherCoursesSpecifiedTimeTag, getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime),
(weightOfMinimiseBookingOfLocationByOtherTeachersTag, getWeightOfMinimiseBookingOfLocationByOtherTeachers),
(weightOfMinimiseDeviationFromTimeslotRequestTag, getWeightOfMinimiseDeviationFromTimeslotRequest),
(weightOfMinimiseInterCampusMigrationsOfStudentsTag, getWeightOfMinimiseInterCampusMigrationsOfStudents),
(weightOfMinimiseInterCampusMigrationsOfTeachersTag, getWeightOfMinimiseInterCampusMigrationsOfTeachers),
(weightOfMinimiseStudentBodyCombinationsTag, getWeightOfMinimiseStudentBodyCombinations),
(weightOfMinimiseTeachersLocusOperandiTag, getWeightOfMinimiseTeachersLocusOperandi),
(weightOfMinimiseWasteOfScarceFacilitiesTag, getWeightOfMinimiseWasteOfScarceFacilities)
]
data LessonCriteriaWeights w = MkLessonCriteriaWeights {
getWeightOfAreResourcesReused :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfGreatestMinimumConsecutiveLessons :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfGreatestRemainingCourseLessons :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfGreatestSynchronisedCourseSetSize :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfIsCoreKnowledgeRequirement :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfIsSpecialistInTopic :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMatchCourseClassSizeToLocationCapacity :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMaximiseRelativeFacilityUtilisation :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseBookingOfLocationByOtherTeachers :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseDeviationFromTimeslotRequest :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseInterCampusMigrationsOfStudents :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseInterCampusMigrationsOfTeachers :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseStudentBodyCombinations :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseTeachersLocusOperandi :: ExecutionConfiguration.CriterionWeight.CriterionWeight w,
getWeightOfMinimiseWasteOfScarceFacilities :: ExecutionConfiguration.CriterionWeight.CriterionWeight w
} deriving (Eq, Show)
instance (Eq w, Num w) => ToolShed.SelfValidate.SelfValidator (LessonCriteriaWeights w) where
getErrors lessonCriteriaWeights = ToolShed.SelfValidate.extractErrors [
(
ExecutionConfiguration.CriterionWeight.areAllZero lessonCriteriaWeights,
"The weight of @ least one lesson-criterion must be non-zero"
)
]
instance Num w => Data.Default.Default (LessonCriteriaWeights w) where
def = MkLessonCriteriaWeights {
getWeightOfAreResourcesReused = Data.Default.def,
getWeightOfGreatestMinimumConsecutiveLessons = Data.Default.def,
getWeightOfGreatestRemainingCourseLessons = Data.Default.def,
getWeightOfGreatestSynchronisedCourseSetSize = Data.Default.def,
getWeightOfIsCoreKnowledgeRequirement = Data.Default.def,
getWeightOfIsSpecialistInTopic = Data.Default.def,
getWeightOfMatchCourseClassSizeToLocationCapacity = Data.Default.def,
getWeightOfMaximiseRelativeFacilityUtilisation = Data.Default.def,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = Data.Default.def,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = Data.Default.def,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = Data.Default.def,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = Data.Default.def,
getWeightOfMinimiseDeviationFromTimeslotRequest = Data.Default.def,
getWeightOfMinimiseInterCampusMigrationsOfStudents = Data.Default.def,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = Data.Default.def,
getWeightOfMinimiseStudentBodyCombinations = Data.Default.def,
getWeightOfMinimiseTeachersLocusOperandi = Data.Default.def,
getWeightOfMinimiseWasteOfScarceFacilities = Data.Default.def
}
instance (HXT.XmlPickler w, Ord w, Real w) => HXT.XmlPickler (LessonCriteriaWeights w) where
xpickle = HXT.xpDefault Data.Default.def . HXT.xpElem tag $ HXT.xpWrap (
\(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) -> MkLessonCriteriaWeights a b c d e f g h i j k l m n o p q r,
\MkLessonCriteriaWeights {
getWeightOfAreResourcesReused = weightOfAreResourcesReused,
getWeightOfGreatestMinimumConsecutiveLessons = weightOfGreatestMinimumConsecutiveLessons,
getWeightOfGreatestRemainingCourseLessons = weightOfGreatestRemainingCourseLessons,
getWeightOfGreatestSynchronisedCourseSetSize = weightOfGreatestSynchronisedCourseSetSize,
getWeightOfIsCoreKnowledgeRequirement = weightOfIsCoreKnowledgeRequirement,
getWeightOfIsSpecialistInTopic = weightOfIsSpecialistInTopic,
getWeightOfMatchCourseClassSizeToLocationCapacity = weightOfMatchCourseClassSizeToLocationCapacity,
getWeightOfMaximiseRelativeFacilityUtilisation = weightOfMaximiseRelativeFacilityUtilisation,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = weightOfMaximiseStudentClassSizeOverCourseClassSize,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = weightOfMaximiseStudentClassSizeOverLocationCapacity,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = weightOfMinimiseBookingOfLocationByOtherTeachers,
getWeightOfMinimiseDeviationFromTimeslotRequest = weightOfMinimiseDeviationFromTimeslotRequest,
getWeightOfMinimiseInterCampusMigrationsOfStudents = weightOfMinimiseInterCampusMigrationsOfStudents,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = weightOfMinimiseInterCampusMigrationsOfTeachers,
getWeightOfMinimiseStudentBodyCombinations = weightOfMinimiseStudentBodyCombinations,
getWeightOfMinimiseTeachersLocusOperandi = weightOfMinimiseTeachersLocusOperandi,
getWeightOfMinimiseWasteOfScarceFacilities = weightOfMinimiseWasteOfScarceFacilities
} -> (
weightOfAreResourcesReused,
weightOfGreatestMinimumConsecutiveLessons,
weightOfGreatestRemainingCourseLessons,
weightOfGreatestSynchronisedCourseSetSize,
weightOfIsCoreKnowledgeRequirement,
weightOfIsSpecialistInTopic,
weightOfMatchCourseClassSizeToLocationCapacity,
weightOfMaximiseRelativeFacilityUtilisation,
weightOfMaximiseStudentClassSizeOverCourseClassSize,
weightOfMaximiseStudentClassSizeOverLocationCapacity,
weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
weightOfMinimiseBookingOfLocationByOtherTeachers,
weightOfMinimiseDeviationFromTimeslotRequest,
weightOfMinimiseInterCampusMigrationsOfStudents,
weightOfMinimiseInterCampusMigrationsOfTeachers,
weightOfMinimiseStudentBodyCombinations,
weightOfMinimiseTeachersLocusOperandi,
weightOfMinimiseWasteOfScarceFacilities
)
) $ HXT.xp18Tuple (
xpickle' weightOfAreResourcesReusedTag
) (
xpickle' weightOfGreatestMinimumConsecutiveLessonsTag
) (
xpickle' weightOfGreatestRemainingCourseLessonsTag
) (
xpickle' weightOfGreatestSynchronisedCourseSetSizeTag
) (
xpickle' weightOfIsCoreKnowledgeRequirementTag
) (
xpickle' weightOfIsSpecialistInTopicTag
) (
xpickle' weightOfMatchCourseClassSizeToLocationCapacityTag
) (
xpickle' weightOfMaximiseRelativeFacilityUtilisationTag
) (
xpickle' weightOfMaximiseStudentClassSizeOverCourseClassSizeTag
) (
xpickle' weightOfMaximiseStudentClassSizeOverLocationCapacityTag
) (
xpickle' weightOfMinimiseBookingAtAnotherCoursesSpecifiedTimeTag
) (
xpickle' weightOfMinimiseBookingOfLocationByOtherTeachersTag
) (
xpickle' weightOfMinimiseDeviationFromTimeslotRequestTag
) (
xpickle' weightOfMinimiseInterCampusMigrationsOfStudentsTag
) (
xpickle' weightOfMinimiseInterCampusMigrationsOfTeachersTag
) (
xpickle' weightOfMinimiseStudentBodyCombinationsTag
) (
xpickle' weightOfMinimiseTeachersLocusOperandiTag
) (
xpickle' weightOfMinimiseWasteOfScarceFacilitiesTag
) where
xpickle' = HXT.xpDefault Data.Default.def . (`HXT.xpAttr` HXT.xpickle)
instance (Eq criterionWeight, Num criterionWeight) => ExecutionConfiguration.CriterionWeight.CriterionWeights (LessonCriteriaWeights criterionWeight) where
areAllZero lessonCriteriaWeights = ExecutionConfiguration.CriterionWeight.areAllZero $ map (($ lessonCriteriaWeights) . snd) associationList
instance Control.DeepSeq.NFData criterionWeight => Control.DeepSeq.NFData (LessonCriteriaWeights criterionWeight) where
rnf (MkLessonCriteriaWeights x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17) = Control.DeepSeq.rnf [x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17]
calculateWeightedMean :: (
Fractional weightedMean,
Real criterionValue,
Real criterionWeight
)
=> LessonCriteriaWeights criterionWeight
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> ExecutionConfiguration.Criterion.Criterion criterionValue
-> Control.Monad.Writer.Writer [Maybe criterionValue] weightedMean
calculateWeightedMean MkLessonCriteriaWeights {
getWeightOfAreResourcesReused = weightOfAreResourcesReused,
getWeightOfGreatestMinimumConsecutiveLessons = weightOfGreatestMinimumConsecutiveLessons,
getWeightOfGreatestRemainingCourseLessons = weightOfGreatestRemainingCourseLessons,
getWeightOfGreatestSynchronisedCourseSetSize = weightOfGreatestSynchronisedCourseSetSize,
getWeightOfIsCoreKnowledgeRequirement = weightOfIsCoreKnowledgeRequirement,
getWeightOfIsSpecialistInTopic = weightOfIsSpecialistInTopic,
getWeightOfMatchCourseClassSizeToLocationCapacity = weightOfMatchCourseClassSizeToLocationCapacity,
getWeightOfMaximiseRelativeFacilityUtilisation = weightOfMaximiseRelativeFacilityUtilisation,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = weightOfMaximiseStudentClassSizeOverCourseClassSize,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = weightOfMaximiseStudentClassSizeOverLocationCapacity,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = weightOfMinimiseBookingOfLocationByOtherTeachers,
getWeightOfMinimiseDeviationFromTimeslotRequest = weightOfMinimiseDeviationFromTimeslotRequest,
getWeightOfMinimiseInterCampusMigrationsOfStudents = weightOfMinimiseInterCampusMigrationsOfStudents,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = weightOfMinimiseInterCampusMigrationsOfTeachers,
getWeightOfMinimiseStudentBodyCombinations = weightOfMinimiseStudentBodyCombinations,
getWeightOfMinimiseTeachersLocusOperandi = weightOfMinimiseTeachersLocusOperandi,
getWeightOfMinimiseWasteOfScarceFacilities = weightOfMinimiseWasteOfScarceFacilities
} areResourcesReused minimumConsecutiveLessons remainingCourseLessons synchronisedCourseSetSize isCoreKnowledgeRequirement isSpecialistInTopic matchOfCourseClassSizeToLocationCapacity relativeFacilityUtilisation studentClassSizeOverCourseClassSize studentClassSizeOverLocationCapacity bookingAtAnotherCoursesSpecifiedTime bookingOfLocationByOtherTeachers deviationFromTimeslotRequest interCampusMigrationsOfStudents interCampusMigrationsOfTeachers studentBodyCombinations teachersLocusOperandi wasteOfScarceFacilities = ExecutionConfiguration.Criterion.calculateWeightedMean [
(areResourcesReused, weightOfAreResourcesReused),
(minimumConsecutiveLessons, weightOfGreatestMinimumConsecutiveLessons),
(remainingCourseLessons, weightOfGreatestRemainingCourseLessons),
(synchronisedCourseSetSize, weightOfGreatestSynchronisedCourseSetSize),
(isCoreKnowledgeRequirement, weightOfIsCoreKnowledgeRequirement),
(isSpecialistInTopic, weightOfIsSpecialistInTopic),
(matchOfCourseClassSizeToLocationCapacity, weightOfMatchCourseClassSizeToLocationCapacity),
(relativeFacilityUtilisation, weightOfMaximiseRelativeFacilityUtilisation),
(studentClassSizeOverCourseClassSize, weightOfMaximiseStudentClassSizeOverCourseClassSize),
(studentClassSizeOverLocationCapacity, weightOfMaximiseStudentClassSizeOverLocationCapacity),
(bookingAtAnotherCoursesSpecifiedTime, weightOfMinimiseBookingAtAnotherCoursesSpecifiedTime),
(bookingOfLocationByOtherTeachers, weightOfMinimiseBookingOfLocationByOtherTeachers),
(deviationFromTimeslotRequest, weightOfMinimiseDeviationFromTimeslotRequest),
(interCampusMigrationsOfStudents, weightOfMinimiseInterCampusMigrationsOfStudents),
(interCampusMigrationsOfTeachers, weightOfMinimiseInterCampusMigrationsOfTeachers),
(studentBodyCombinations, weightOfMinimiseStudentBodyCombinations),
(teachersLocusOperandi, weightOfMinimiseTeachersLocusOperandi),
(wasteOfScarceFacilities, weightOfMinimiseWasteOfScarceFacilities)
]
type Mutator w = LessonCriteriaWeights w -> LessonCriteriaWeights w
zeroWeightOfAreResourcesReused :: Num w => Mutator w
zeroWeightOfAreResourcesReused lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfAreResourcesReused = minBound
}
zeroWeightOfGreatestMinimumConsecutiveLessons :: Num w => Mutator w
zeroWeightOfGreatestMinimumConsecutiveLessons lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfGreatestMinimumConsecutiveLessons = minBound
}
zeroWeightOfGreatestRemainingCourseLessons :: Num w => Mutator w
zeroWeightOfGreatestRemainingCourseLessons lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfGreatestRemainingCourseLessons = minBound
}
zeroWeightOfGreatestSynchronisedCourseSetSize :: Num w => Mutator w
zeroWeightOfGreatestSynchronisedCourseSetSize lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfGreatestSynchronisedCourseSetSize = minBound
}
zeroWeightOfIsCoreKnowledgeRequirement :: Num w => Mutator w
zeroWeightOfIsCoreKnowledgeRequirement lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfIsCoreKnowledgeRequirement = minBound
}
zeroWeightOfIsSpecialistInTopic :: Num w => Mutator w
zeroWeightOfIsSpecialistInTopic lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfIsSpecialistInTopic = minBound
}
zeroWeightOfMatchCourseClassSizeToLocationCapacity :: Num w => Mutator w
zeroWeightOfMatchCourseClassSizeToLocationCapacity lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMatchCourseClassSizeToLocationCapacity = minBound
}
zeroWeightOfMaximiseRelativeFacilityUtilisation :: Num w => Mutator w
zeroWeightOfMaximiseRelativeFacilityUtilisation lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMaximiseRelativeFacilityUtilisation = minBound
}
zeroWeightOfMaximiseStudentClassSizeOverCourseClassSize :: Num w => Mutator w
zeroWeightOfMaximiseStudentClassSizeOverCourseClassSize lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = minBound
}
zeroWeightOfMaximiseStudentClassSizeOverLocationCapacity :: Num w => Mutator w
zeroWeightOfMaximiseStudentClassSizeOverLocationCapacity lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = minBound
}
zeroWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime :: Num w => Mutator w
zeroWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = minBound
}
zeroWeightOfMinimiseBookingOfLocationByOtherTeachers :: Num w => Mutator w
zeroWeightOfMinimiseBookingOfLocationByOtherTeachers lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseBookingOfLocationByOtherTeachers = minBound
}
zeroWeightOfMinimiseDeviationFromTimeslotRequest :: Num w => Mutator w
zeroWeightOfMinimiseDeviationFromTimeslotRequest lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseDeviationFromTimeslotRequest = minBound
}
zeroWeightOfMinimiseInterCampusMigrationsOfStudents :: Num w => Mutator w
zeroWeightOfMinimiseInterCampusMigrationsOfStudents lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseInterCampusMigrationsOfStudents = minBound
}
zeroWeightOfMinimiseInterCampusMigrationsOfTeachers :: Num w => Mutator w
zeroWeightOfMinimiseInterCampusMigrationsOfTeachers lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseInterCampusMigrationsOfTeachers = minBound
}
zeroWeightOfMinimiseStudentBodyCombinations :: Num w => Mutator w
zeroWeightOfMinimiseStudentBodyCombinations lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseStudentBodyCombinations = minBound
}
zeroWeightOfMinimiseTeachersLocusOperandi :: Num w => Mutator w
zeroWeightOfMinimiseTeachersLocusOperandi lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseTeachersLocusOperandi = minBound
}
zeroWeightOfMinimiseWasteOfScarceFacilities :: Num w => Mutator w
zeroWeightOfMinimiseWasteOfScarceFacilities lessonCriteriaWeights = lessonCriteriaWeights {
getWeightOfMinimiseWasteOfScarceFacilities = minBound
}
normalise :: (
Fractional w,
Ord w,
Real w
) => Mutator w
normalise lessonCriteriaWeights
| ExecutionConfiguration.CriterionWeight.areAllZero lessonCriteriaWeights = lessonCriteriaWeights
| otherwise = MkLessonCriteriaWeights {
getWeightOfAreResourcesReused = normaliseCriterionWeight $ getWeightOfAreResourcesReused lessonCriteriaWeights,
getWeightOfGreatestMinimumConsecutiveLessons = normaliseCriterionWeight $ getWeightOfGreatestMinimumConsecutiveLessons lessonCriteriaWeights,
getWeightOfGreatestRemainingCourseLessons = normaliseCriterionWeight $ getWeightOfGreatestRemainingCourseLessons lessonCriteriaWeights,
getWeightOfGreatestSynchronisedCourseSetSize = normaliseCriterionWeight $ getWeightOfGreatestSynchronisedCourseSetSize lessonCriteriaWeights,
getWeightOfIsCoreKnowledgeRequirement = normaliseCriterionWeight $ getWeightOfIsCoreKnowledgeRequirement lessonCriteriaWeights,
getWeightOfIsSpecialistInTopic = normaliseCriterionWeight $ getWeightOfIsSpecialistInTopic lessonCriteriaWeights,
getWeightOfMatchCourseClassSizeToLocationCapacity = normaliseCriterionWeight $ getWeightOfMatchCourseClassSizeToLocationCapacity lessonCriteriaWeights,
getWeightOfMaximiseRelativeFacilityUtilisation = normaliseCriterionWeight $ getWeightOfMaximiseRelativeFacilityUtilisation lessonCriteriaWeights,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = normaliseCriterionWeight $ getWeightOfMaximiseStudentClassSizeOverCourseClassSize lessonCriteriaWeights,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = normaliseCriterionWeight $ getWeightOfMaximiseStudentClassSizeOverLocationCapacity lessonCriteriaWeights,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = normaliseCriterionWeight $ getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime lessonCriteriaWeights,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = normaliseCriterionWeight $ getWeightOfMinimiseBookingOfLocationByOtherTeachers lessonCriteriaWeights,
getWeightOfMinimiseDeviationFromTimeslotRequest = normaliseCriterionWeight $ getWeightOfMinimiseDeviationFromTimeslotRequest lessonCriteriaWeights,
getWeightOfMinimiseInterCampusMigrationsOfStudents = normaliseCriterionWeight $ getWeightOfMinimiseInterCampusMigrationsOfStudents lessonCriteriaWeights,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = normaliseCriterionWeight $ getWeightOfMinimiseInterCampusMigrationsOfTeachers lessonCriteriaWeights,
getWeightOfMinimiseStudentBodyCombinations = normaliseCriterionWeight $ getWeightOfMinimiseStudentBodyCombinations lessonCriteriaWeights,
getWeightOfMinimiseTeachersLocusOperandi = normaliseCriterionWeight $ getWeightOfMinimiseTeachersLocusOperandi lessonCriteriaWeights,
getWeightOfMinimiseWasteOfScarceFacilities = normaliseCriterionWeight $ getWeightOfMinimiseWasteOfScarceFacilities lessonCriteriaWeights
}
where
normaliseCriterionWeight = ExecutionConfiguration.CriterionWeight.mkCriterionWeight . (
/ ExecutionConfiguration.CriterionWeight.deconstruct (
maximum $ map (($ lessonCriteriaWeights) . snd ) associationList
)
) . ExecutionConfiguration.CriterionWeight.deconstruct
perturbWeights :: (
Enum f,
Fractional f,
Real f,
Show f,
System.Random.Random f,
System.Random.RandomGen randomGen
)
=> randomGen
-> f
-> Mutator f
perturbWeights _ 0 lessonCriteriaWeights = lessonCriteriaWeights
perturbWeights randomGen changeMagnitude lessonCriteriaWeights
| changeMagnitude < 0 = error $ "WeekDaze.ExecutionConfiguration.LessonCriteriaWeights.perturbWeights:\t" ++ show ExecutionConfiguration.OptimiseLessonCriteriaWeights.changeMagnitudeTag ++ " must be positive; " ++ show changeMagnitude ++ "."
| otherwise = normalise lessonCriteriaWeights {
getWeightOfAreResourcesReused = reduceBy a $ getWeightOfAreResourcesReused lessonCriteriaWeights,
getWeightOfGreatestMinimumConsecutiveLessons = reduceBy b $ getWeightOfGreatestMinimumConsecutiveLessons lessonCriteriaWeights,
getWeightOfGreatestRemainingCourseLessons = reduceBy c $ getWeightOfGreatestRemainingCourseLessons lessonCriteriaWeights,
getWeightOfGreatestSynchronisedCourseSetSize = reduceBy d $ getWeightOfGreatestSynchronisedCourseSetSize lessonCriteriaWeights,
getWeightOfIsCoreKnowledgeRequirement = reduceBy e $ getWeightOfIsCoreKnowledgeRequirement lessonCriteriaWeights,
getWeightOfIsSpecialistInTopic = reduceBy f $ getWeightOfIsSpecialistInTopic lessonCriteriaWeights,
getWeightOfMatchCourseClassSizeToLocationCapacity = reduceBy g $ getWeightOfMatchCourseClassSizeToLocationCapacity lessonCriteriaWeights,
getWeightOfMaximiseRelativeFacilityUtilisation = reduceBy h $ getWeightOfMaximiseRelativeFacilityUtilisation lessonCriteriaWeights,
getWeightOfMaximiseStudentClassSizeOverCourseClassSize = reduceBy i $ getWeightOfMaximiseStudentClassSizeOverCourseClassSize lessonCriteriaWeights,
getWeightOfMaximiseStudentClassSizeOverLocationCapacity = reduceBy j $ getWeightOfMaximiseStudentClassSizeOverLocationCapacity lessonCriteriaWeights,
getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime = reduceBy k $ getWeightOfMinimiseBookingAtAnotherCoursesSpecifiedTime lessonCriteriaWeights,
getWeightOfMinimiseBookingOfLocationByOtherTeachers = reduceBy l $ getWeightOfMinimiseBookingOfLocationByOtherTeachers lessonCriteriaWeights,
getWeightOfMinimiseDeviationFromTimeslotRequest = reduceBy m $ getWeightOfMinimiseDeviationFromTimeslotRequest lessonCriteriaWeights,
getWeightOfMinimiseInterCampusMigrationsOfStudents = reduceBy n $ getWeightOfMinimiseInterCampusMigrationsOfStudents lessonCriteriaWeights,
getWeightOfMinimiseInterCampusMigrationsOfTeachers = reduceBy o $ getWeightOfMinimiseInterCampusMigrationsOfTeachers lessonCriteriaWeights,
getWeightOfMinimiseStudentBodyCombinations = reduceBy p $ getWeightOfMinimiseStudentBodyCombinations lessonCriteriaWeights,
getWeightOfMinimiseTeachersLocusOperandi = reduceBy q $ getWeightOfMinimiseTeachersLocusOperandi lessonCriteriaWeights,
getWeightOfMinimiseWasteOfScarceFacilities = reduceBy r $ getWeightOfMinimiseWasteOfScarceFacilities lessonCriteriaWeights
}
where
(a : b : c : d : e : f : g : h : i : j : k : l : m : n : o : p : q : r : _) = System.Random.randomRs (1, succ changeMagnitude) randomGen
reduceBy randomValue = ExecutionConfiguration.CriterionWeight.mkCriterionWeight . (/ randomValue) . ExecutionConfiguration.CriterionWeight.deconstruct