In this paper, the genetic algorithms are applied to the optimization problem of magnet sorting in an electron storage ring, according to which the objectives are set so that the closed orbit distortion and beta beating can be minimized and the dynamic aperture maximized. The sorting of dipole, quadrupole and sextupole magnets is optimized while the optimization results show the power of the application of genetic algorithms in magnet sorting.