Reasonable roadway layout is the fundamental measure to reduce the difficulty of roadway support and improve the stability of surrounding rock. The particle swarm optimization and analytic hierarchy process (PSO-AHP) algorithm of reasonable layout of roadway under the three-dimensional field was proposed, and an engineering verification was carried out in Weijiadi coal mine. The results showed that, The dip angle α1 and azimuth angle α2 affect the distribution of the deviatoric stress of the roadway surrounding rock. Under different stress field, the sensitivity of surrounding rock to α1 and α2 are different. Changing the more sensitive layout parameters can minimize the deviatoric stress and improve the stability of roadway. The PSO-AHP optimization algorithm takes the deviatoric stress as the index to calculate the layout parameters of different parts of the roadway, and then determines the optimal layout parameters through the evaluation function. The roadway of 1104 working face was arranged with the optimal parameters obtained by PSO-AHP optimization algorithm. Compared with the original layout scheme, the deviatoric stress of surrounding rock was reduced and the position of maximum deviatoric stress is transferred. The optimum layout of roadway was combined with an asymmetric support which had a good application effect.