Magnetic field imaging (MFI) is a technique to record contact free the magnetic field distribution and estimate the underlying source distribution in the heart. Currently, the cardiomagnetic fields are recorded with superconducting quantum interference devices (SQUIDs), which are restricted to the inside of a cryostat filled with liquid helium or nitrogen. New room temperature optical magnetometers allow less restrictive sensor positioning, which raises the question of how to optimally place the sensors for robust field reconstruction. The objective in this study is to develop a generic object-oriented framework for optimizing sensor arrangements (sensor positions and orientations) which supports the necessary constraints of a limited search volume (only outside the body) and the technical minimum distance of sensors (e.g. 1 cm). In order to test the framework, a new quasi-continuous particle swarm optimizer (PSO) component is developed as well as an exemplary goal function component using the condition number (CN) of the leadfield matrix. Generic constraint handling algorithms are designed and implemented, that decompose complex constraints into basic ones. The constraint components interface to an operational exemplary optimization strategy which is validated on the magnetocardiographic sensor arrangement problem. The simulation setup includes a three compartment boundary element model of a torso with a fitted multi-dipole heart model. The results show that the CN, representing the reconstruction robustness of the inverse problem, can be reduced with our optimization by one order of magnitude within a sensor plane (the cryostat bottom) in front of the torso compared to a regular sensor grid. Reduction of another order of magnitude is achieved by optimizing sensor positions on the entire torso surface. Results also indicate that the number of sensors may be reduced to 20-30 without loss of robustness in terms of CN. The original contributions are the generic reusable framework and exemplary components, the quasicontinuous PSO algorithm with constraint support and the composite constraint handling algorithms.