Prolog辅导 | COMP 3120 Assignment 2 Develop a degree planner in Prolog

COMP 3120 Fall 2019 Assignment 2
Develop a degree planner in Prolog
As you know, there are several requirements to complete a university degree:  You must complete a certain number of courses  You must complete some specific courses  You must complete a number of courses from specified categories  You can only take a course if you have completed its pre-requisites.
Your Prolog program will return an ordered list of courses that together complete a university degree.
Main requirements (7 marks):
To complete this assignment you will need to:
1. Decide on a specific 4-year university program you will model in your program.
I highly suggest choosing the Bachelor’s degree in Computing Science (BCS) at TRU. The requirements are found
2. Represent the courses and program requirements in Prolog. You will have to decide on how detailed and
accurate you want to be. You can represent each course as an atom, e.g. comp3120, or you can use a predicate,
e.g. course(comp, 3120, ‘Programming Languages’), or use some other representation that works for your
program. Just be consistent and clear.
3. You will need to identify the course prerequisites and ensure that a course is not taken before a prerequisite,
i.e., a course cannot precede its prerequisite in the output list.
4. The final output must be an ordered list of specific courses. You can’t just have placeholders like “general
elective”. You do not need to include every single TRU course (!), just a reasonable number of representatives is
Challenges (1 mark each, maximum 10 marks total):  Add an argument to your main rule that breaks up the output list into groups (sub-lists) of 3, 4, or 5. These
groups each represent a set of courses taken in one semester. Pre-requisites must be taken in a previous group.  Represent other requirements like “upper year standing” (e.g. COMP 3450), or co-requisites.  Format the output nicely in a human-readable manner, rather than just returning a long list.
 If you can think of some other element or aspect to implement that warrants being considered a challenge (and
worth a mark), let me know!
YOU MUST have a comment in your code that lists which of the main requirements you can fulfill, as well as any of
the challenges you have implemented.
Coding Style
Clarity matters. Appropriate function names, function types/signatures, and comments (where necessary) are all
expected. Marks will be reduced if the code is hard to understand.
If you include any code from any source other than yourself, you must cite the source. Usually a weblink is sufficient. Do
not overdo this, but it is okay to use a small amount of code that helps you solve a specific problem. It is definitely better
to learn from outside code and write it on your own, however. Any other form of copying will be dealt with formally.
Hints As with anything, start small, e.g., try to design a degree that only requires 3 courses.  For some things you can use either facts or rules to represent them, e.g. determining whether a course is a
computing course. You can make a rule that recognizes the COMP part of the id, or you can simple list a fact for
each course that is considered a computing course. Obviously the rule will be less code, but the facts will be
simpler to write.  Recursion is not that hard to add to a Prolog rule, but it is easy to make mistakes with recursion. Only use it
when you need it, and test thoroughly on simple examples.  Keep your rules simple. Even if a rule needs several arguments to define the problem instance and/or hold
intermediate calculations, make sure that they are all necessary and that you are focusing on one goal.  Singleton variables (only one occurrence of a variable in a rule) are never useful. Avoid them.  Accuracy is great for this assignment but producing something functional is more important.  Test driven development is great with Prolog. For any rule, think of tests to ensure it does what you expect.
Those tests do not have to be related to the main problem. Just make sure that new bit of code is working
properly on its own.