Agent based model for distributed optimization of microgrids operation