# How to optimize student happiness in group work?

There are $n$ students in a class, and they must be divided into, say, $k$ groups. Each student ranks the other students in order of preference of working together. Is there a way to generally optimize student happiness (where happiness is based on working with preferred teammates). We could assume for simplicity that happiness is correlated in a simple (say linear) way with preference rank of group members.

When will there be a unique optimal grouping?

What if the happiness is not linearly correlated to preference rank?

-
The answer is simple: never assign group work! (I know some terrible stories.) –  Qiaochu Yuan Mar 11 '10 at 8:22
@Qiaochu: frivolous and amusing, but of course completely incorrect. –  Loop Space Mar 11 '10 at 11:40

This is a generalization of the stable roommate problem (which is the same thing where $k = n/2$, ie, groups of 2). In general, there exist groups in which under any pair of groups contain members who would both like to switch teams.