5

I am currently writing a program which maps students to courses. Currently, I am using a SAT-Solver, but I am trying to implement a polynomial time / non greedy algorithm which solves the following sub-problem:

  • There are students (50-150)
  • There are subjects (10-20), e.g. 'math', 'biology', 'art'
  • There are courses per subject (at least one), e.g. 'math-1', 'math-2', 'biology-1', 'art-1', 'art-2', 'art-3'
  • A student selects some (fixed) subjects (10-12) and for each subject the student has to be assigned to exactly one of the existing courses (if possible). It does not matter which course 'math-1' or 'math-2' is being selected.
  • The courses have a maximum number of allowed students (20-34)
  • Each course is in a fixed block (= timeslot 1 to 13)
  • A student may not be assigned to courses being in the same block

I am now describing what I have done so far.

(1) Ignoring the course-student-limit

I was able to solve this with the hungarian algorithm / bipartite matching. Each student may be computed individually by modelling it as following:

  • left nodes represent the subjects 'math', 'biology', 'art' (of the student)
  • right nodes represent the blocks '1', '2', .... '13'
  • an edge is inserted for each course from 'subject' to 'block'

This way the student is assigned for every subject to a course while not attending courses which are in the same block. But course-limits are ignored.

(2) Ignoring the selected subjects of the student

I was able to solve this with a max-flow-algorithm. For each student the following is modelled:

  • Layer 1: From source to each student with a flow of 13
  • Layer 2: From each student to his/her personal block with a flow of 1
  • Layer 3: From each student-block to each course in that block with flow 1
  • Layer 4: From each course to the sink with 'max-student-limit'

This way the student selects arbitrary courses and the course-limit is fullfilled. But he/she may be unlucky and be assigned to 'math-1', 'math-2' and 'math-3' ignoring the subjects 'biology' and 'art'.

(3) Greedy Hungarian

Another idea I had was to match one student at a time with the hungarian algorithm and adjusting the weights so that 'more empty courses' are preferred. For example one could model:

  • left nodes are subjects of the student
  • right nodes are blocks
  • for each course insert an edge from subject to the block of the course with weight = number of free seats

And then computing a Maximum-Weight-Matching.

I would really appreciate any suggestions / help.

Thank you!

galath
  • 5,717
  • 10
  • 29
  • 41
Benjamin
  • 51
  • 4
  • You probably would be better of asking on programmers.stackexchange.com as they deal with algorithms and generally a higher level of abstraction than SO. Otherwise, could you show the code (if any) that is specifically causing you trouble? – Lilith Daemon Jul 06 '15 at 19:41
  • It is not a programming problem (no code needed), it is an algorithmic/modelling-problem and a theoretical-problem. The question is if it is possible to model the problem and solve it in polynomial time or if the problem is already NP-complete. But I am new here, so maybe I am wrong and it belongs to 'programmers...'. – Benjamin Jul 06 '15 at 19:58
  • 2
    Algorithm questions are on-topic both on SO and Programmers. Please read: **[What goes on Programmers.SE? A guide for Stack Overflow](http://meta.programmers.stackexchange.com/q/7182/22815)**. –  Jul 06 '15 at 20:04
  • This is a hard problem. I don't have proof that it's NP-complete, but it is definitely very hard. – Yay295 Jul 07 '15 at 03:23
  • Actually, what if you just assign students to classes until the class is full? So the first 20 or so students are assigned to math-1, the next ~20 to math-2, and so on. Then do the same for the other subjects. I think you need more students though. If you have 10-20 subjects, each one has at least one class, and each class can hold 20-34 students, that's at least 200 open seats. – Yay295 Jul 07 '15 at 03:40
  • @Yay295 This is not optimal because of the blocks (timeslots) of the courses which are fixed. For example if the courses are grouped in blocks like [M-1, B-1] [A-2] [M-3, M-2, A-1], it may happen when filling M-1 with student who selected also B, that these student are not able to visit a B-Course anymore. – Benjamin Jul 07 '15 at 09:25
  • Ah, yeah. I expected there would be some problems with that plan. – Yay295 Jul 08 '15 at 05:28
  • 1
    Do you want to determine whether an assignment is possible? or do you want a best configuration in case there is no assignment? In the second case, I think it would be clearer to expand on what to minimize, for example, the total number of student preferences that could not be satisfied. – galath Jul 11 '15 at 13:15
  • @galath you are right, I thought it would follow from (1). Both your suggestions are fine. I wan't to minize the student-preferences that could not be satisfied. But determining wether an assignment is possible is also leading to a working algorithm, because I can lower the course-limits until no such assignment is possible anymore. – Benjamin Jul 12 '15 at 08:22

0 Answers0