Economic disptch in networks containing microgrids with distributed generation resources is of great importance. In these networks, power generation sources like solar plants and wind turbines are distributed in different locations, making it essential to optimize the allocation of generated energy. One of the main challenges in this regard is optimal schedule of resources and proper distribution of generation. To solve this challenge, evolutionary-based optimization algorithms can be used. In this research, by using the Particle Swarm Optimization (PSO) algorithm in the MATLAB software platform, a 33-bus IEEE test network with microgrids is studied. By considering technical constraints, the energy is optimally distributed, while the amount of unsupplied energy remains at an acceptable level. It is shown that optimal energy management with the constraint of unsupplied energy aims to improve the performance and stability of the power grid, including reducing energy costs and increasing system efficiency.