Algorithms for energy harvesting systems