Determination of an optimal topology with a predefined number of cavities