I have a project, it asks me to distribute the courses to the students.All students asks for some of courses but they are only allowed to get some number of them(it could be what they demand,less than it or just 0),all the courses have quotas and i need to find whether the perfect match (all the quotas are full-filled and students got what they are allowed to) exists or not- if exists the output of that matching.
I just get the input and stored it in objects so far.There is a time restriction in the project,what i don't know is where to start.Any suggestions or method for this project?
I think i should implement bipartite matching algorithm.I am new in c++,so do I need to implement both node class and edge class ? Or should I use adjacency list ? Which one is faster in running ?
For example , a student asks for lessons numbered 3,4 and 5 but he is allowed to take 2 lessons, so algorithm should give 2 of these choices if there is perfect matching possibility.
What i imagined by bipartite problem was this but i think it is hard to implement this. https://i.stack.imgur.com/wtJ6o.jpg
1.student wants 3 ,4 system allows him to take 2 lessons
2.student wants 1,2,3,4 system allows him to take 3 lessons
3.student wants 1,2,3,4 system allows him to take 2 lessons
4.student wants 1,3,5 system allows him to take 2 lessons
5.student wants 2,5 system allows him to take 1 lessons
1.lesson's quota = 2
2.lesson's quota = 1
3.lesson's quota = 2
4.lesson's quota = 3
5.lesson's quota = 2
I just wrote this ,this might not be the best example.
One possible solution is = 1 -> (3,4) 2->(1,2,4) 3->(3,4) 4->(1,5) 5->(5)
Another is = 1 -> (3,4) 2->(1,2,4) 3->(1,4) 4->(3,5) 5->(5)
there might be more , I don't know.
(student -> lessons)
Since one student can be assigned more than one course, I don't think that the problem can be solved by simple maximal bipartite matching algorithm.
This problem is a type of transportation problem, where the courses are the
sources
, and students are thedestinations
. The quota of each course is itscapacity
, thedemand
for each student is the number of lessons that system allows him.EDIT:
You can formulate the transportation problem by following modification:
Split the lessons such that each lesson has a quote of 1. So in your example case there shall be 10 lessons. Assign the costs as follows: