settlement algorithm