Cost-optimal charging of electric vehicles using real-time pricing