Use minimum number of swaps so each bin contains balls of the same color
Maximal decomposition of an Eulerian directed graph into edge disjoint cycles is NP-Hard, at least according to this book: Algorithms and Applications:
Essays Dedicated to Esko Ukkonen on the Occasion of His 60th Birthday. 

btw, here is an article which is relevant to the problem you seem to be trying to solve: Asymptotically optimal algorithm for the Dutch National flag algorithm.

For $n \le 6$, the paper gives a simple algorithm.