chore: reimagine nudge usage
- scale appropriately for unrestricted sizes - don't behave weirdly for very large rooms
This commit is contained in:
parent
ff5d27cdf3
commit
3ab8be2e0d
@ -244,7 +244,7 @@ data ExamAutoOccurrenceException
|
|||||||
| ExamAutoOccurrenceExceptionNotEnoughSpace
|
| ExamAutoOccurrenceExceptionNotEnoughSpace
|
||||||
| ExamAutoOccurrenceExceptionNoUsers
|
| ExamAutoOccurrenceExceptionNoUsers
|
||||||
| ExamAutoOccurrenceExceptionRoomTooSmall
|
| ExamAutoOccurrenceExceptionRoomTooSmall
|
||||||
deriving (Show, Generic, Typeable)
|
deriving (Show, Eq, Generic, Typeable)
|
||||||
|
|
||||||
instance Exception ExamAutoOccurrenceException
|
instance Exception ExamAutoOccurrenceException
|
||||||
|
|
||||||
@ -291,7 +291,10 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
|
|||||||
currentRatios = Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched calculateRatio)
|
currentRatios = Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched calculateRatio)
|
||||||
currentOccurrences restrictedOccurrences
|
currentOccurrences restrictedOccurrences
|
||||||
calculateRatio :: ExamOccurrenceId -> Natural -> Natural -> Rational
|
calculateRatio :: ExamOccurrenceId -> Natural -> Natural -> Rational
|
||||||
calculateRatio k c m = fromIntegral c % fromIntegral m - eaocNudgeSize * fromIntegral (lineNudges k)
|
calculateRatio k c m = fromIntegral c / (max 1 $ fromIntegral m * sizeModifier)
|
||||||
|
where
|
||||||
|
sizeModifier :: Rational
|
||||||
|
sizeModifier = 1 + eaocNudgeSize * fromIntegral (lineNudges k)
|
||||||
biggestOutlier :: ExamOccurrenceId
|
biggestOutlier :: ExamOccurrenceId
|
||||||
biggestOutlier = fst . List.maximumBy (comparing $ view _2) $ Map.toList currentRatios
|
biggestOutlier = fst . List.maximumBy (comparing $ view _2) $ Map.toList currentRatios
|
||||||
predToPositive :: Natural -> Maybe Natural
|
predToPositive :: Natural -> Maybe Natural
|
||||||
@ -437,7 +440,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
|
|||||||
longestLine :: Natural
|
longestLine :: Natural
|
||||||
-- ^ For scaling costs
|
-- ^ For scaling costs
|
||||||
-- longest restricted line (or 1 if all unrestricted)
|
-- longest restricted line (or 1 if all unrestricted)
|
||||||
longestLine = maybe 1 maximum $ fromNullable restrictedLengths
|
longestLine = maybe numUnassignedUsers maximum $ fromNullable restrictedLengths
|
||||||
|
|
||||||
wordMap :: Map wordId Natural
|
wordMap :: Map wordId Natural
|
||||||
wordMap = Map.fromListWith (+) wordLengths
|
wordMap = Map.fromListWith (+) wordLengths
|
||||||
@ -547,24 +550,24 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
|
|||||||
|
|
||||||
widthCost :: Maybe lineId -> ExamOccurrenceCapacity -> Natural -> Extended Rational
|
widthCost :: Maybe lineId -> ExamOccurrenceCapacity -> Natural -> Extended Rational
|
||||||
widthCost l Unrestricted w
|
widthCost l Unrestricted w
|
||||||
= Finite (fromIntegral w
|
= Finite $ max 1 $ (fromIntegral w - sizeModifier * (fromIntegral extraUsers % List.genericLength unrestrictedLines)) ^ 2
|
||||||
- (fromIntegral extraUsers % List.genericLength unrestrictedLines)
|
|
||||||
- nudgeRatio * fromIntegral longestLine)^2
|
|
||||||
where
|
where
|
||||||
nudgeRatio :: Rational
|
sizeModifier :: Rational
|
||||||
nudgeRatio = maybe 0 (fromIntegral . lineNudge) l * eaocNudgeSize
|
sizeModifier = 1 + maybe 0 (fromIntegral . lineNudge) l * eaocNudgeSize
|
||||||
widthCost l (Restricted lineWidth) w
|
widthCost l (Restricted lineWidth) w
|
||||||
| lineWidth < w = PosInf
|
| lineWidth < w = PosInf
|
||||||
| otherwise = Finite (max 1 . abs $ ((fromIntegral w % fromIntegral lineWidth) - optimumRatio') * fromIntegral longestLine) ^ 2
|
| otherwise = Finite $ max 1 $ ((fromIntegral w / nudgedWidth - optimumRatio) * fromIntegral longestLine) ^ 2
|
||||||
where
|
where
|
||||||
optimumRatio' :: Rational
|
nudgedWidth :: Rational
|
||||||
optimumRatio' = maybe 0 (fromIntegral . lineNudge) l * eaocNudgeSize + optimumRatio
|
nudgedWidth = max 1 $ sizeModifier * fromIntegral lineWidth
|
||||||
|
sizeModifier :: Rational
|
||||||
|
sizeModifier = 1 + maybe 0 (fromIntegral . lineNudge) l * eaocNudgeSize
|
||||||
|
|
||||||
charCost :: [CI Char] -> [CI Char] -> Extended Rational
|
charCost :: [CI Char] -> [CI Char] -> Extended Rational
|
||||||
charCost pA pB = Finite (max 1 $ List.genericLength (pA `lcp` pB) * eaocFinenessCost * fromIntegral longestLine) ^ 2
|
charCost pA pB = Finite (max 1 $ List.genericLength (pA `lcp` pB) * eaocFinenessCost * fromIntegral longestLine) ^ 2
|
||||||
where
|
where
|
||||||
longestLine :: Natural
|
longestLine :: Natural
|
||||||
longestLine = maybe 1 maximum $ fromNullable $ catMaybes
|
longestLine = maybe (sum $ fromIntegral . length <$> users') maximum $ fromNullable $ catMaybes
|
||||||
$ view (_2 . _examOccurrenceCapacityIso) <$> occurrences''
|
$ view (_2 . _examOccurrenceCapacityIso) <$> occurrences''
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user