Abstract-The ongoing trend of increasing product individualization requires more flexible solutions in production systems. Modular robots address this demand since they can be assembled in different ways from a given set of modules. One of the reasons why modular robots are not yet successfully introduced in the market is that it is not clear how to assemble modules such that the robot will be able to achieve a specific task optimally, especially in the presence of obstacles. This problem is challenging since a huge combination of possible assemblies exists and one has to find the optimal trajectory for each of them. We address exactly this issue not by finding optimal solutions for each assembly, but instead pruning the search space: First, we remove assemblies that cannot achieve the task before starting the process of finding optimal trajectories. Second, we exploit the iterative nature of numerical optimization routines by removing assemblies that are not promising in each iteration. We demonstrate that our approach is clearly better compared to finding assemblies by optimizing trajectories for each assembly individually.