A stochastic approach to handle knapsack problems in the creation of ensembles