Maximizing the combination of a series of values

This is a difficult question, but I suspect there is some principle that I can apply to make it simple - I just don’t know what it is.

I need to put presentation slots in a class full of students for a semester. There are several possible dates and several types of presentations. I conducted a survey in which students could evaluate their interest in various topics. What I would like to do is get the best (or at least good) distribution of presentation slots for students.

So what I have:

  • List of 12 Dates
  • List of 18 students
  • A CSV file in which each student (line) has a rating of 1-5 for each date

What I would like to receive:

  • Each student must have one presentation type A ( intro), one of the presentation types B ( figures) and 3 presentation types C ( aims)
  • Each date must have at least 1 of each type of presentation
  • Each date must have no more than 2 type A or type B
  • Try to give students presentations that they praised (4 or 5).

I should note that I understand that this seems like a home problem, but this is real life :-). I thought I could make a class Studentfor each student that contains dates for each type of presentation, but I was not sure that the best way to fill it out would be. In fact, I don’t even know where to start.

+4
source share
1 answer

TL; DR: , : D

. , . , , . , , , . , , , , .

, , 10 ^ 65 . . , , .

- - . , ; , , 4 5.

, ( .. , 5), , ( , , 3), , . , reset, . A B, C A B, C .

- .

, . ; / 3. , X , - , , , 5 + 3 + 3 = 11, 5 + 5 + 4 = 14; 11/14 = 78,6%.

, 95%, , :) , . , , .

​​algorihtm. script ~ 250 , . Github.

...

# Assign a date for a given task to each student, 
# preferring a date that they like and is still free.
def fill(task, lowest_acceptable, spread_weight=0.1, tasks_to_spread="ABC"):
        random_order = range(nStudents) # randomize student order, so everyone
        random.shuffle(random_order)    # has an equal chance to get their first pick
        for i in random_order:
            student = students[i]
            if student.dates[task]: # student is already assigned for this task?
                continue

            # get available dates ordered by preference and how fully booked they are
            preferred = get_favorite_day(student, lowest_acceptable,  
                                         spread_weight, tasks_to_spread)
            for date_nr in preferred:
                date = dates[date_nr]
                if date.is_available(task, student.count, lowest_acceptable == 1):
                    date.set_student(task, student.count)
                    student.dates[task] = date
                    break

# attempt to "fill()" the schedule while gradually lowering expectations
start_at = 5
while start_at > 1:
    lowest_acceptable = start_at
    while lowest_acceptable > 0:
        fill("A", lowest_acceptable, spread_weight, "AAB")
        fill("B", lowest_acceptable, spread_weight, "ABB")
        if lowest_acceptable == 1:
            fill("C", lowest_acceptable, spread_weight_C, "C")
        lowest_acceptable -= 1

, script:

                                      Date                                      
================================================================================
Student |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  10 |  11 |  12 |
================================================================================
   1    |     |  A  |  B  |     |  C  |     |     |     |     |     |     |     |
   2    |     |     |     |     |  A  |     |     |     |     |  B  |  C  |     |
   3    |     |     |     |     |  B  |     |     |  C  |     |  A  |     |     |
   4    |     |     |     |  A  |     |  C  |     |     |     |     |     |  B  |
   5    |     |     |  C  |     |     |     |  A  |  B  |     |     |     |     |
   6    |     |  C  |     |     |     |     |     |     |  A  |  B  |     |     |
   7    |     |     |  C  |     |     |     |     |  B  |     |     |     |  A  |
   8    |     |     |  A  |     |  C  |     |  B  |     |     |     |     |     |
   9    |  C  |     |     |     |     |     |     |     |  A  |     |     |  B  |
   10   |  A  |  B  |     |     |     |     |     |     |  C  |     |     |     |
   11   |  B  |     |     |  A  |     |  C  |     |     |     |     |     |     |
   12   |     |     |     |     |     |  A  |  C  |     |     |     |  B  |     |
   13   |  A  |     |     |  B  |     |     |     |     |     |     |     |  C  |
   14   |     |     |     |     |  B  |     |     |     |  C  |     |  A  |     |
   15   |     |     |  A  |  C  |     |  B  |     |     |     |     |     |     |
   16   |     |     |     |     |     |  A  |     |     |     |  C  |  B  |     |
   17   |     |  A  |     |  C  |     |     |  B  |     |     |     |     |     |
   18   |     |     |     |     |     |     |  C  |  A  |  B  |     |     |     |
================================================================================
Total student satisfaction: 250/261 = 95.00%
+2

Source: https://habr.com/ru/post/1625901/


All Articles