Optimization of networks