Algorithm for thermal plants regulation