Time inconsistency and optimal policies in deterministic and stochastic worlds