In this paper, we present the problem of allocating students to classes in Swiss secondary schools, where students have different profiles due to their level in some fields or to the options they attend. The pedagogical objective is to have a high diversity of profiles within a class and similarity between classes. In order to achieve this goal, the problem is modelled as a resource allocation problem (RAP), where students are resources, using a constraint satisfaction optimisation approach (CSOP). The RAP is then solved in two different ways, with a solver for CSOP, and with an ant colony optimisation algorithm (ACO). Eight real datasets are used to compare their performance. The ACO algorithm provides better solutions than the CSOP solver in a shorter time. Results show that the pheromones used in the ACO help to find better solutions in a much smaller amount of time. The short computation time enables the school's directors to simulate different compositions of their future classes before having the final results of the last exams.