Sorting People into Groups based on Votes

后端 未结 2 414
我寻月下人不归
我寻月下人不归 2021-01-21 09:35

I have a problem with finding a algorithm for sorting a dataset of people. I try to explain as detailed as possible:

The story starts with a survey. A bunch of people, l

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 10:08

    My algorithm would be something like this:

    mainloop
     wishlevel = 1
      loop
       Distribute people into all projects according to wishlevel wish
       loop through projects, counting population
        If population exceeds maximum
         Distribute excess non-redistributed people into their wishlevel+1 projects that are under-populated
         tag distributed people as 'redistributed' to avoid moving again
        endif
       endloop
      wishlevel = wishlevel + 1
     loop until wishlevel == 3    
    mainloop until no project exceeds max population
    

    This should make several passes through the data set until everything is evened out. This algorithm may result in an endless loop if you restrict redistribution of already-redistributed people in the event that one project fills up with such people as the algorithm progresses, so you might try it without that restriction.

提交回复
热议问题