Optimal power generation in microgrids using agent-based technology