A reinforcement learning approach to system modularization under constraints