I'm modelling a university curriculum timetable with Answer Set Programming (Clingo). The requirements are that each lesson must be asssigned to a specific week , day and start /end hours until the total hours are reached.
In a day there are max 8 hours and each lesson is 2 hours minimum. Also the scheduled lessons are until the 10th week.
week(1..10). time(9,11;11,13;14,16;16,18).
So first I generated each assigned lesson slot
TotalHours { assigned(Week,Day,Start,End,Course,Teacher) : day(Day), time(Start,End), week(Week) } TotalHours :-
lesson(Course,Teacher,TotalHours).
After that for other requirements and rules I needed to find the last course assigned in the timetable. I don't know if this is a good way but I was able to find a solution
MaxWeek = #max {Week : assigned(Week,_,_,_,Course,_)},
MaxDay = #max {Day : assigned(MaxWeek,Day,_,_,Course,_)},
MaxStart= #max {Start : assigned(MaxWeek,MaxDay,Start,_,Course,_)},
assigned(_,_,_,_,Course,_).
I'm new to ASP and so far I couldn't find a good way to find the second last lesson of the course assigned in the timetable(Week,Day,Start,End) needed for other schedule requirements.
So given for example
assigned(1,Monday,9,11,History,John) , assigned(1,Tuesday,11,13,Math,Smith), assigned(4,Tuesday,16,18,History,John),assigned(5,Monday,11,13,History,John)
I want to find the second last lesson of History which is
assigned(4,Tuesday,16,18)
Any tips or solutions is really appreciated