Optimal flow control in manufacturing systems