Skip to content
Snippets Groups Projects
Commit 25d91e84 authored by beekmannju85374's avatar beekmannju85374 :writing_hand:
Browse files

fixed fairRest algo

parent 4f292ce0
No related branches found
No related tags found
1 merge request!8Master
......@@ -89,17 +89,17 @@ generateSchedules rooms startDay endDay professors = groups
days = [d | d <- [readDay startDay..readDay endDay], dayOfWeek d == Thursday, d `notElem` uniHolidays (readDay startDay) (readDay endDay)]
-- generate all possible presentations
presentations = [Presentation room day proj prof | day <- days,
room <- rooms,
prof <- professors,
(null (availableDays prof) && day `notElem` unavailableDays prof) ||
(null (unavailableDays prof) && day `elem` availableDays prof),
proj <- projects prof]
room <- rooms,
prof <- professors,
(null (availableDays prof) && day `notElem` unavailableDays prof) ||
(null (unavailableDays prof) && day `elem` availableDays prof),
proj <- projects prof]
-- generate all combinations from each presentation in presentations with every other presentation, filter out unsuitable or impossible presentations
-- the possible dates must be >= the number of professors and their projects in order to combine them
-- the possible dates x room must be >= the number of professors and their projects in order to combine them
groups
| length days * length rooms < projectsLen = error "not enough possible dates or rooms for scheduling"
| otherwise = map (splitIntoGroups (fairRest projectsLen) . sortByRoom) $ combinationsFast projectsLen (sort presentations)
| otherwise = map (splitIntoGroups (fairRest projectsLen) . sortByRoom) $ combinationsFast projectsLen (sort presentations) -- try complexity with sort and without
-- after combining the presentations, split each list into the fairest groups
-- a presentationgroup should have 3 to 5 projects each
......@@ -108,18 +108,27 @@ generateSchedules rooms startDay endDay professors = groups
-- if 5 is the fairest with rest 1 change to resultDif because you cannot have groupings of 6
-- 3a + 4b + 5c = n
-- if 3,4 or 5 are equal, does findEven change if the other equal number is chosen?
-- guard order is important!
fairRest :: Int -> Int
fairRest n
= if first result == 5 && second result == 1 then first resultDif else first result
| first result == 5 && second result == 1 = first resultDif -- last group cannot be 6 since its not allowed
| first resultDif == 3 && third result == 1 = first result -- last group cannot be 2 since its not allowed
| second result <= 1 = first result
| second result > 1 = first resultDif
| otherwise = error "critical math error in fairRest" -- is not possible
where
result = minimumBy (compare `on` second) modResults
resultDif = minimumBy (compare `on` third) modResults
modResult x = (x, n `mod` x, x - (n `mod` x))
modResults = map modResult [5,4,3]
modResults = map modResult [5,4]
first (x, _, _) = x
second (_, x, _) = x
third (_, _, x) = x
-- if first result == 5 && second result == 1 then first resultDif else first result
-- ( n, x, n%x, x - (n%x) )
fairRestDebug :: Int -> [(Int, Int,Int,Int)]
fairRestDebug n = result
......@@ -171,14 +180,14 @@ findEven presentations rooms
-- filters according to the rules above findEven
checkEven :: [[Presentation]] -> [Room] -> Bool
checkEven presentations rooms
| even (length presentations) = all (\group -> length (nub (map room group)) == 1) presentations
| even projectsLen =
let countRooms = map (countRoom (concat presentations)) rooms
in all (== head countRooms) (tail countRooms)
| odd projectsLen = all (\r -> abs (countRoom (concat presentations) r - (projectsLen `div` length rooms)) <= 1) rooms
| otherwise = error "unaccounted for amount of rooms and or presenations, fix in function checkEven, maybe needs stricter guards"
where
projectsLen = length $ concat presentations
| even (length presentations) = all (\group -> length (nub (map room group)) == 1) presentations
| even projectsLen =
let countRooms = map (countRoom (concat presentations)) rooms
in all (== head countRooms) (tail countRooms)
| odd projectsLen = all (\r -> abs (countRoom (concat presentations) r - (projectsLen `div` length rooms)) <= 1) rooms
| otherwise = error "unaccounted for amount of rooms and or presenations, fix in function checkEven, maybe needs stricter guards"
where
projectsLen = length $ concat presentations
countRoom :: [Presentation] -> Room -> Int
countRoom presentations r = length $ filter (\p -> room p == r) presentations
......@@ -187,9 +196,9 @@ countRoom presentations r = length $ filter (\p -> room p == r) presentations
-- leave schedule unchanged for old professors, if it is not possible the plan must be recalculated
addProfessor :: Professor -> [Room] -> String -> String -> [[Presentation]] -> [[[Presentation]]]
addProfessor prof rooms startDay endDay oldPresentations =
if null newGroups
then error "Cannot add a new professor with the existing presentation list. Need to recalculate all presentations."
else map (splitIntoGroups (fairRest projectsLen) . sortByRoom) newGroups
if null newGroups
then error "Cannot add a new professor with the existing presentation list. Need to recalculate all presentations."
else map (splitIntoGroups (fairRest projectsLen) . sortByRoom) newGroups
where
oldPresentationsFlat = concat oldPresentations --removes grouping
projectsLen = length oldPresentationsFlat + length (projects prof)
......@@ -209,9 +218,9 @@ addProfessor prof rooms startDay endDay oldPresentations =
addProfUnavailability :: Professor -> [String] -> [Room] -> String -> String -> [[Presentation]] -> [[[Presentation]]]
addProfUnavailability prof unavailables rooms startDay endDay oldPresentations =
if null newGroups
then error "Cannot add new unavailability for professor with the existing presentation list. Need to recalculate all presentations."
else newGroups
if null newGroups
then error "Cannot add new unavailability for professor with the existing presentation list. Need to recalculate all presentations."
else newGroups
where
oldPresentationsFlat = concat oldPresentations
updatedProf = prof { unavailableDays = readDays unavailables ++ unavailableDays prof }
......
No preview for this file type
No preview for this file type
......@@ -13,6 +13,7 @@
\begin{document}
\noindent \textbf{Vortragsgruppe S1}\\
Beginn: 14:00\\
\\
\begin{tabular}{@{}llll}
Datum & Projektgruppe & Dozent/in & Raum\\
04.04.24 & Project 2 & Professor 2 & H\\
......@@ -22,11 +23,12 @@ Beginn: 14:00\\
\\\\
\noindent \textbf{Vortragsgruppe S2}\\
Beginn: 14:00\\
\\
\begin{tabular}{@{}llll}
Datum & Projektgruppe & Dozent/in & Raum\\
25.04.24 & Project 5 & Professor 5 & H\\
04.04.24 & Project 4 & Professor 4 & P\\
11.04.24 & Project 3 & Professor 3 & P\\
25.04.24 & Project 5 & Professor 5 & P\\
\end{tabular}
\\\\
\end{document}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment