Optimal topology control and power allocation for minimum energy consumption in consensus networks