Generation Optimization for Mircogrid