Simulating how animals learn: a new modelling framework applied to the process of optimal foraging