Optimal stopping for the run-time self-adaptation of software systems