Optimization of energy consumption in swarms of robots