Optimisation of flow schemes for ion-exchange separations by dynamic programming