snippetsqlMinor
How to model "Courses prerequisites" for a university?
Viewed 0 times
coursesprerequisitesforuniversityhowmodel
Problem
I am trying to model a courses structure and dependencies of a university.
For example, in the Computer Engineering department you need to do Data Structures before doing Artificial Intelligence. But you also need to finish Introduction to Logic OR Mathematical Logic and Proofs.
I was thinking about using a table for the courses (Id, Course Number, Course Name, Hours, Professor) and another table for the dependencies.
There lies the problem: How to model this dependencies/prerequisites? The only -viable- solution that I came up with was making this as a string, written in plain English; but that clearly doesn't seem to be a decent solution and I also believe that it violates the atomicity principle.
Notice that the prerequisites of Artificial Intelligence are of the form
I don't know if this is relevant or not, but I will use MySQL.
For example, in the Computer Engineering department you need to do Data Structures before doing Artificial Intelligence. But you also need to finish Introduction to Logic OR Mathematical Logic and Proofs.
I was thinking about using a table for the courses (Id, Course Number, Course Name, Hours, Professor) and another table for the dependencies.
There lies the problem: How to model this dependencies/prerequisites? The only -viable- solution that I came up with was making this as a string, written in plain English; but that clearly doesn't seem to be a decent solution and I also believe that it violates the atomicity principle.
Notice that the prerequisites of Artificial Intelligence are of the form
IA <- DS && (IL || MLP), but other courses will have a different structure like Calculus 2, that requires analytical geometry and calculus 1 done before: C2 <- AG && C1.I don't know if this is relevant or not, but I will use MySQL.
Solution
You have some Courses:
You need to combine one or more of these Courses with a logical operator:
You may also need to combine some of these combinations (so changing the COMBINATION_COURSES table):
where one and only one of course_id and sub_combination_id is not null.
A Course may have one of the combinations as a prerequisite (so changing the COMBINATIONS table):
EDIT
So, given your original examples your tables would be populated:
Course 1 - Artificial Intelligence has a prerequisite of the Combination 12. Combination 12 is Course 2 - Data Structures AND Combination 11. Combination 11 is Course 3 - Introduction to Logic OR Course 4 - Mathematical Logic and Proofs.
Hence, the prerequisite of Course 1 - Artificial Intelligence is Course 2 - Data Structures AND (Course 3 - Introduction to Logic OR Course 4 - Mathematical Logic and Proofs).
This structure should allow you to store any prerequisite that is the any logical combination of any number of courses.
COURSES
-------
course_id
course_number
course_nameYou need to combine one or more of these Courses with a logical operator:
COMBINATIONS
------------
combination_id
logical_operator (AND, OR or NOT)
COMBINATION_COURSES
-------------------
combination_id
course_idYou may also need to combine some of these combinations (so changing the COMBINATION_COURSES table):
COMBINATION_COURSES
-------------------
combination_id
course_id
sub_combination_idwhere one and only one of course_id and sub_combination_id is not null.
A Course may have one of the combinations as a prerequisite (so changing the COMBINATIONS table):
COURSES
-------
course_id
course_number
course_name
prerequisite_combination_idEDIT
So, given your original examples your tables would be populated:
COURSES
=======
course_id course_name prerequisite_combination_id
--------- ------------------------------ ---------------------------
1 Artificial Intelligence 12
2 Data Structures
3 Introduction to Logic
4 Mathematical Logic and Proofs
5 Calculus 1
6 Calculus 2 13
7 Analytical Geometry
COMBINATIONS
============
combination_id logical_operator
-------------- ----------------
11 OR
12 AND
13 AND
COMBINATION_COURSES
===================
combination_id course_id sub_combination_id
-------------- --------- ------------------
11 3
11 4
12 2
12 11
13 7
13 5Course 1 - Artificial Intelligence has a prerequisite of the Combination 12. Combination 12 is Course 2 - Data Structures AND Combination 11. Combination 11 is Course 3 - Introduction to Logic OR Course 4 - Mathematical Logic and Proofs.
Hence, the prerequisite of Course 1 - Artificial Intelligence is Course 2 - Data Structures AND (Course 3 - Introduction to Logic OR Course 4 - Mathematical Logic and Proofs).
This structure should allow you to store any prerequisite that is the any logical combination of any number of courses.
Code Snippets
COURSES
-------
course_id
course_number
course_nameCOMBINATIONS
------------
combination_id
logical_operator (AND, OR or NOT)
COMBINATION_COURSES
-------------------
combination_id
course_idCOMBINATION_COURSES
-------------------
combination_id
course_id
sub_combination_idCOURSES
-------
course_id
course_number
course_name
prerequisite_combination_idCOURSES
=======
course_id course_name prerequisite_combination_id
--------- ------------------------------ ---------------------------
1 Artificial Intelligence 12
2 Data Structures
3 Introduction to Logic
4 Mathematical Logic and Proofs
5 Calculus 1
6 Calculus 2 13
7 Analytical Geometry
COMBINATIONS
============
combination_id logical_operator
-------------- ----------------
11 OR
12 AND
13 AND
COMBINATION_COURSES
===================
combination_id course_id sub_combination_id
-------------- --------- ------------------
11 3
11 4
12 2
12 11
13 7
13 5Context
StackExchange Database Administrators Q#107628, answer score: 3
Revisions (0)
No revisions yet.