Optimization of reactive power compensation in distribution networks