A Win-Win Algorithm for Learning the Flexibility of Aggregated Residential Appliances