Realization of universal optimal quantum machines by projective operators and stochastic maps