The purpose of this research is to form learning groups that are intra-homogeneous (a high level of similarity across student GPAs inside a group), inter-homogeneous (similarity or balance in the degree of homogeneity between groups), and balanced in size. The algorithm proposed for this purpose treats the learning group formation as an assignment-type optimization problem where it seeks to find a feasible least-cost assignment of a given set of students to a given set of learning groups. It is referred to as GAGF (Generalized Assignment Strategy for Group Formation). It is based on an efficient cost model, which performs three tasks: measuring the cost of assigning students to a learning group, relating each improvement in assignment cost to increased intra-group homogeneity and group size balance, and bringing the intra-homogeneity of the groups to a reference value (a specific level of homogeneity), which improves inter-homogeneity. Experimental results have shown that the GAGF algorithm is effective at constructing intra- and inter-homogeneous learning groups with balanced sizes. It was found that using GAGF attained an improvement of more than 29% in intra-group homogeneity when compared to both related work and self-formation methods. It significantly improved inter-group homogeneity, outperforming related works by 79.75%.