I am trying to create a simple scheduler in Prolog that takes a bunch of courses along with the semesters they offer, and a user-defined course rating. These inputs turn into facts like
course('CS 4812','Quantum Information Processing',1.0882353,s2012).
course('Math 6110','Real Analysis I',0.5441176,f2011).
where the third entry is an estimate. My database currently has about 60 classes, but I want the program to be able to process more in the end. I'm having trouble getting my DP implementation to work on non-trivial input. The answers are correct, but the time spent is in the same order as the brute force algorithm. I handle memoization with a dynamic predicate:
:- dynamic(stored/6).
memo(Result,Schedule,F11,S12,F12,S13) :-
stored(Result,Schedule,F11,S12,F12,S13) -> true;
dpScheduler(Result,Schedule,F11,S12,F12,S13),
assertz(stored(Result,Scheduler,F11,S12,F12,S13)).
Arguments dpSchedulerare the optimal schedule (a tuple of the list of classes and its evaluation), the classes selected so far, and how many classes are left for the fall of 2011, Spring 2012, Fall 2012 and Spring 2013 semester. When the planner has a competition schedule, he gets an estimate with help evalSchedulethat simply sums up the class ratings.
dpScheduler((Acc,X),Acc,0,0,0,0) :-
!, evalSchedule(X,Acc).
I broke it dpSchedulerevery semester, but they all look the same. Here is the proposal for the fall of 2011, the first semester is selected.
dpScheduler(Answer,Acc,N,B,C,D) :-
!, M is N - 1,
getCourses(Courses,f2011,Acc),
lemma([Head|Tail],Courses,Acc,M,B,C,D),
findBest(Answer,Tail,Head).
The predicate lemmacalculates all subgoals.
lemma(Results,Courses,Acc,F11,S12,F12,S13) :-
findall(Result,
(member(Course,Courses), memo(Result,[Course|Acc],F11,S12,F12,S13)),
Results).
, , . , Prolog, Prolog , , , . .