In this paper, a genetic algorithm is developed in which each individual is represented not by a string but by a matrix: in this way the entire population is represented by a 3-D matrix. Such a representation is particularly useful for solving optimization problems with many discrete variables: such as, for example, the optimal allocation and sizing of distributed generation systems or the optimal compensation in a distribution system through the installation, in a prefixed number of nodes, of batteries of fixed or modulated capacitors, having different sizes. In these cases, the unknowns of the optimization process are the nodes where the apparatus can be installed and their rated sizes to be chosen in a discrete set of values. The adopted representation allows setting up a group of new operators whose application implies a strong increase of the search space size and consequently the number of algorithm parameters increases as well. The primary objective of this paper is that of evaluating the algorithm's performance and, with this aim, it has been applied to the problem of the compensation of electrical distribution networks.