optimize markov chain