Optimization of flow networks for oil production