I made a rating / team picker using only weighted kapm per class. It's robust and converges quickly. I can talk you through it.
http://dl.dropbox.com/u/54614942/teampicker_example.txt
Bear in mind that when we talk about balanced teams, for 6v6 we mean having the best two scouts separated, the weaker of those pairs given the best demoman, and then the soldiers handed out in any way that doesn't break it (usually only 1 way will break it). You could assign medics by Elo (I can't test Elo because I handpicked most teams in my mix group). That is, the question can be simplified drastically.
In 9v9 random is pretty good, and any simple kapm per class with classes assigned in order of relevance-of-kapm would be perfectly adequate. This is the Einstein solution, as simple as possible.