Distributed Generators(DG) is an important part of smart grid. To solve the optimization allocation problem of distributed generator, this article put forward a two-stage multidimensional dynamic model, which calculated and selected node loss-voltage sensitivity for DG site selection in order to reduce network loss in its first stage. Then, considering allocation cost and system reliability, this article use the Electromagnetism-like Mechanism(ELM) algorithm for DG capacity selection. In order to improve the performance of ELM, this article mainly improved force calculation, particle update and local search, which can enhance the convergence and optimization efficiency of the ELM. Finally, through the IEEE39 node system simulation and result analysis, it shows that this method can get good results in optimization allocation of DG.