Stochastic Control and Optimization of Networks