Distributed generation becomes more and more important in modern power systems. However, the increasing use of distributed generators causes the concerns on the increasing system risk due to their likely failure or uncontrollable power outputs based on such renewable energy sources as wind and the sun. This work for the first time formulates an optimal power flow problem by considering controllable and uncontrollable distributed generators in power networks. The problem for the cases of single and multiple generator failures is addressed as an example. The methods are presented to find its power output solution of controllable online generators via particle swarm optimization and group search optimizer for coping with the difficult scenarios in a power network. The proposed methods are tested on an IEEE 14-bus system, and several population initialization strategies are investigated and compared for the algorithms. The simulation results confirm their effectiveness for optimal power management and effective control of a power network.