Dynamic protocol for demand management of heterogeneous resources with convex cost functions