OPTIMIZING THE DEMAND AND DISTRIBUTION OF POWER IN SMART GRIDS