title: Algorithm to assign workers to teams based on workers preferences
body: <p>We have <code>N</code> workers and they should be assigned to one of <code>M</code> teams. Each team can have a maximum of <code>K</code> workers. Each worker ranks the teams in order of preference, starting from <code>1</code> for the most preferred team to <code>M</code> for the least preferred team. Now the problem is to find a matching, so that workers end up in the team they prefer most, given the constraint that each team can have a maximum of <code>K</code> workers. </p>
  
  <p>At first I thought, this is an <a href="https://en.wikipedia.org/wiki/Assignment_problem" rel="nofollow noreferrer" title="Assignment problem">Assignment problem</a> that could be solved using the <a href="https://en.wikipedia.org/wiki/Hungarian_algorithm" rel="nofollow noreferrer" title="Hungarian algorithm">Hungarian Algorithm</a>. But then I realised that the Hungarian Algorithm can only be used if each worker is assigned to exactly one item. But in my case several workers can be assigned to the same team. </p>
  
  <p>Now I'm unsure what kind of problem this really is. Is this a (multiple) <a href="https://en.wikipedia.org/wiki/Knapsack_problem" rel="nofollow noreferrer">Knapsack problem</a> or <a href="https://en.wikipedia.org/wiki/Bin_packing_problem" rel="nofollow noreferrer">Bin packing problem</a> ? What kind of algorithm could I use to solve that problem? </p>