Evolutionary dynamics of sex determination