Quasi-deterministic theory of semiconductor laser gain switching