This research developed a model to optimize cascade reservoirs operation with the constraint of ecological flow. The model objective function is the total hydropower output and the conventional constraints include water level, discharges etc. In order to minimize the negative influence of reservoir operation on river ecosystem, ecological flow demand of downstream river was taken into account. The developed model was applied to two cascade reservoirs of Yalongjiang River in the southwest China. The optimal operation scheme was achieved through genetic algorithm, where total maximum power output was received, and all the constraints including ecological flow demand were satisfied. This scheme was confirmed by a habitat model as the weighted usable area of fish habitat would increase dramatically compared to the conventional reservoir operation.