Optimization of production planning and control in environments with complex flows