The optimal design of flexible manufacturing systems