algorithm to change power source