Speed dating algorithm

后端 未结 9 627
深忆病人
深忆病人 2021-02-04 10:19

I work in a consulting organization and am most of the time at customer locations. Because of that I rarely meet my colleagues. To get to know each other better we are going to

9条回答
  •  爱一瞬间的悲伤
    2021-02-04 10:37

    I wouldn't bother with genetic algorithms. Instead, I would do the following, which is a slight refinement on repeated perfect shuffles.

    While (there are two people who haven't met):

    1. Consider the graph where each node is a guest and edge (A, B) exists if A and B have NOT sat at the same table. Find all the connected components of this graph. If there are any connected components of size < tablesize, schedule those connected components at tables. Note that even this is actually an instance of a hard problem known as Bin packing, but first fit decreasing will probably be fine, which can be accomplished by sorting the connected components in order of biggest to smallest, and then putting them each of them in turn at the first table where they fit.
    2. Perform a random permutation of the remaining elements. (In other words, seat the remaining people randomly, which at first will be everyone.)
    3. Increment counter indicating number of rounds.

    Repeat the above for a while until the number of rounds seems to converge.

提交回复
热议问题