Distributed Algorithms for the Optimal Design of Wireless Networks