Optimization and control method for smart charging of