A two stage algorithm is proposed in this paper to optimize cost of generation with application to a virtual power plant. First stage of the algorithm presents a methodology to draw a hierarchy for the choice of distributed generators based on the cost of generation. Second stage of the algorithm optimizes generation to minimize cost. An Additive Increase and Multiplicative Decrease algorithm, which is already used for optimization in microgrids is improved further and is presented as Modified Additive Increase Multiplicative Decrease algorithm and is applied in the second stage of the algorithm for optimization. The Modified Additive Increase Multiplicative Decrease algorithm is validated by implementing to schedule generation of distributed generators with intermittent power availability in a Virtual Power Plant in grid connected mode to optimize the cost of generation. The Modified AIMD algorithm is proved to be much more effective than the original AIMD algorithm. © 2016 The Authors.