Collective probabilities algorithm for surface hopping calculations