Opinion-based optimal group formation