advanced 'Knapsack problem'

Hello and a nice day,
all I am asking for is a small pointer:

I thought about writing a program that helps dividing a bulk of students in several classes.

[tr][td]Each student has some attributs:

  • Gender
  • Second language
  • 3 ‘Friend wishes’ (They would like to be in class with those 3 other students)
  • Performance category
  • one or two more…

Then we have a fixed set of classes.
For example:
4 classes, each is supposed to hold approximately the same student count
Each class is supposed to have as much boys as girls
2 classes offer both languages, the other two each just one,
The performance category is supposed to be mixed too.
And so on…[/td][/tr]

In the moment I just throw the students in the classes randomly and then try to optimize with an arbitrary count of steps.
In each step I pick a student and try to see if he can be placed better; or may improves the breakdown when he swaps with an other student.

But there must be a better solution out there.
I have no idea about graphs but I guess there is already an algorithm i can use?
I found some things like ‘Graph Partitioning’ but nothing I could apply. (Maybe I just overlooked the solution…)

Can you tell me what I should google for? Any reduction for ‘Graph Partitioning’ or an other keyword,
that would be a big help!

-ClaasJG