The use of distributed generation and demand response programs in smart grids implies management and integration of these resources when they are interconnected with the main power system. In the present paper, it is defined a methodology that can be used by the Virtual Power Player in order to aggregate and schedule the resources. The aggregated producers and consumers are optimally managed, making them profitable and fully integrated in the network operation. The focus is given to the partition clustering algorithm, k-means, which is applied to several operation scenarios. The clustering of the resources is made in order to define the remuneration of each defined group, which corresponds to a distinct demand response program or remuneration group. The case study includes 20310 consumers and 548 distributed generation units, in 648 distinct operation scenarios.