Optimal foraging strategies can be learned