an dam solver for BP problem