The Optimal Foraging Game and tutorial was developed by Hopscotch Interactive, Inc. in collaboration with Corey Goldman (EEB). Programming by Thomas Lynch and Alejandro Lynch; exercise design by Mike Dennison.

Hummingbird images © Robert Tuckerman.

Optimal Foraging book by Andrew Horn, Dalhousie University.

Feedback: If you have questions about this Game, or suggestions for how to improve it, please contact Mike Dennison,

Optimal Foraging


Andrew G. Horn

Dalhousie University


1. Optimization in Biology


One of the most satisfying aspects of biology is the exquisite fit between biological adaptations and their functions. The match is both qualitative and quantitative. Vertebrate eyes are as well designed as cameras for collecting visual information, not just because they have camera-like features like lenses, adjustable apertures, and photosensitive backings, but also because those features have the quantitatively engineered precision. The depth of the eye matches the focal length of the lens; the iris adjusts to let in precisely enough light to neither overexpose nor underexpose the retinal image.


Optimality modelling is an important tool for quantifying the design of adaptations. The techniques of optimality modelling are largely borrowed from engineering and economics. The key concept of optimality is that everything is a balance between costs and benefits. The trick of designing any tool is to balance the costs and benefits in such a way that one maximizes one's net gain.


The application of optimality theory to explaining animal behaviour was a major breakthrough in biology, and gave rise to the field known as behavioural ecology. Behavioural ecology looks at the behaviours of animals as their toolbox for increasing their survival and reproductive success. It has applied optimality modeling to everything from social systems and communication to maintenance and reproduction. Foraging theory is perhaps the easiest area to apply optimality theory, because the benefits and costs can both usually be modelled in terms that are relatively easy to understand and measure, like energy, nutrients, and time.

2. Natural Selection


Many adaptations are so optimally designed they seem like they were planned by an engineer. We don't need to invoke an engineer to explain them, though, thanks to Darwin's theory of evolution by natural selection. The theory starts with the natural variability of organisms. Some of this variability is genetically encoded, and hence passed on from parents to offspring. Because of competition for breeding opportunities in successive generations, not all individuals will survive; there's limited food, predators are about, and so on.

All these potential pitfalls will inevitably prevent some individuals from surviving and breeding. The ones that do happen to survive are those are better at getting limited food, avoiding predators, and so on. This selection of these individuals is natural. It is more complex, but no more remarkable, than sifting sand grains through a sieve. Just as sifting leaves the bigger grains behind, the organisms that are left to breed again are those that have adaptations which increase the likelihood that they'll survive and reproduce.

Adaptive Behaviour

This process of natural selection isn't goal-oriented, although it's easy to get that impression, particularly in the case of animal behaviour. Because of natural selection, animals tend to behave in ways that maximize their reproductive success. However, that doesn't mean that this is their goal in any conscious sense.

Behavioural adaptations are particularly prone to this misunderstanding, because behaviour often involves goal-directed mechanisms. Some of these mechanisms are simple; maggots orient toward light using a mechanism as simple as the one in guided missiles. Other mechanisms are complex: a chimpanzee may have to think to retrieve a ball just out of reach. Both of these organisms are designed in a way that is adaptive, but the program in the animal that achieves that doesn't play any role in natural selection.

3. Optimality Models

Any optimization problem has three main features: a behavioural decision, a currency, and constraints.

Behavioural Decisions

The many things that animals do can be broken down into a series of decisions: when to fight, when to mate, what food to search for, and so on. An optimally designed animal should make the right decisions. If an optimality modeller tackles all these decisions at once, his or her model will quickly get out of hand. So it's best to limit the model to a simple decision: should the animal stay in this patch or go? Is it worth waiting for a female to respond to my signal or should I save energy and stop signalling? This approach may be a little unrealistic, but complications can always be added later.


Ultimately, the benefit to the animal of solving a problem, in an evolutionary sense, is increased survival and reproductive success. But in order to do that, an animal must overcome a lot of subsidiary hurdles: eat enough food, find a mate, raise its young, and so on. The success of the animal in overcoming each of these hurdles ultimately translates into increased reproductive success, but we won't learn much about behaviour if we try to figure out how a hummingbird can sip a flower to best increase its reproductive success -- that result is too far removed from the action. Instead we must select measure of its immediate success, a currency, that is a stand-in for and will ultimately result in higher survival and reproductive success. In the patch model, as in most foraging models, the currency is the rate of energy gain -- the more energy you can get in a limited time, the greater your reproductive success.


In a perfect world, animals could just suck food and mates out of thin air. But the world isn't perfect; it presents animals with certain realities. The patch problem you're dealing with now, for example, presents two ubiquitous limits on our lives. First, the curve of diminishing returns is a reality in just about every sphere of life: whether you're a hummingbird sucking on a flower or a farmer harvesting a crop, eventually resources begin to run out. Second, resources are usually scattered across space; it takes a while to get from one flower to the next or to buy more seed and plant a new crop, and during that time you aren't earning any energy. So the diminishing gain curve and travel time are the two constraints of this optimality model.

4. The Components of the Patch Model

We might be able to predict how a hummingbird should forage by using a long-winded verbal argument, but a simple optimality model is more efficient. It makes our assumptions and predictions quantitative and explicit. Remember the three main features of an optimality model: a behavioural decision, a currency, and constraints.

Behavioural Decisions

Once a hummingbird has started foraging, it's mainly faced with a simple decision: should it stay in the patch and forage or move on to another patch? Graphically, we're asking at what point on the x (time) axis the hummingbird should change patches.


Hummingbirds have limited time to gain as much energy as they can for their expensive metabolism, so energy gain per unit time is overwhelmingly important for their survival and is the obvious candidate for our currency. Choosing the appropriate currency isn't always this easy. For instance, energy efficiency, i.e., energy gain per unit of energy spent, is often a more appropriate currency, but for hummingbirds in this situation rate of energy gain will do fine. Here the currency is shown graphically by how high we rise in the y (energy) axis relative to how far we have moved on the x (time) axis.


The two main constraints of the patch model are:

  1. Travel time-- the length of time it takes to get to a patch before your energy can start climbing the gain curve, and
  2. Gain curve -- this increases rapidly at first and then levels out.

5. Marginal Value Theorem

As in any optimality model, you arrive at the predictions of the marginal value theorem by following through the logic of its constraints. Imagine you're a hummingbird that's just left a flower patch. Time is ticking relentlessly, and as it does you move steadily rightward along the x-axis. Your energy gain is shown by any rises in the y-axis as you confront each constraint in turn: Travel time. It takes a while to get from one patch to another, and during that time, you don't get any food. Gain curve. Once you're in a patch, you get more and more energy. But gradually, for every unit of time you spend, your gain in energy gets less and less. That might happen for several reasons, for example because you're depleting the patch or because the food gets harder to find. Remember what the object of the game is: to get as much energy per time spent as you can. On the graph, that means for every unit on the x-axis, you'll want to go as high on the y-axis as you can. In other words, wherever you end up on the gain curve, you want the line A-B to be as steep as possible.

Early Gain

At first, the line A-B gets steeper and steeper. Don't quit the patch now; you're on a roll.

Staying Too Long

But after a while, the line A-B starts falling again. That means even though you're still getting more energy, your energy gain relative to your time spent is getting smaller.

Optimal Gain

So the solution is to leave at the point a little earlier, where line A-B is at its maximum, which is where the line just barely touches the curve, i.e., where it's tangent to it. Those of you who are familiar with calculus will recognize this as the point where the instantaneous slope, or derivative, of the gain curve equals the maximum possible slope of a line from the origin tangential to the curve. The economics term for derivative is marginal value; hence the name of the marginal value theorem.

6. Habitat Variation

By varying the constraints of our model a bit, we can make it more realistic and apply it to more situations.

Travel Costs

Habitats may vary in how densely patches are distributed. For example, in habitat A, to your right, patches are densely packed, so travel times are short. In habitat B, patches are sparse, so travel times are long. Even though the patches are of similar quality in the two habitats (their gain curves are identical), our little trick with leaning line A-B against the curve shows that the patch residence times will differ: the longer the travel time, the longer the patch residence time should be. This result makes intuitive sense, because the time that you spend actually getting food becomes more valuable the longer your down time during travelling is going to be.

7. Hummingbird Test of Marginal Value Theorem

Graham Pyke tested the marginal value theorem on hummingbirds (Selasphorus spp.) foraging on alpine flowers called Scarlet Gilia (Ipomopsis aggregata). He also watched hummingbirds through his window as they visited artificial feeders that he constructed with green styrofoam stems and red surgical needle caps for flowers. Scarlet Gilia flowers grow on spikes called inflorescences that Pyke's artificial feeders simulated. Each inflorescence, or feeder, was considered one patch.


To test the marginal value theorem, Pyke had to show that the hummingbirds left patches when their expected rate of return from staying in the patch dropped to the average rate of gain for the habitat. Measuring the average rate of gain for the habitat was easy. Pyke simply counted the number of flowers hummingbirds visited in a certain length of time. From the amount of nectar contained in each flower and its sucrose concentration, he could then calculate the hummingbird's average rate of energy gain.

Measuring the hummingbird's expected gain within a patch was trickier, since Pyke initially had no way to tell what the hummingbird was thinking. Instead, he assumed that the hummingbirds estimated their rate of gain by one or a combination of three things: 1) how much nectar was extracted from the last flower to be visited), 2) the number of flowers they had visited so far, and 3) the likelihood that the next flower they visited would be a revisit. He then calculated how many flowers hummingbirds should visit per patch based on each of these pieces of information or their combination.


The fit between the observed and predicted data was striking, but only when all three pieces of information were used to calculate the departure rule. On inflorescences of eight flowers, the birds left after probing 4.68 flowers on average (predicted: 4.5 flowers); on inflorescences of twelve flowers, they left after probing 5.10 flowers (predicted: 5.5 flowers). The hummingbirds foraged as predicted by the marginal value theorem.

8. Selected Reading

  1. Adams, G. K., K.K. Watson, J. Pearson, and M. L. Platt. 2012. Neuroethology of decision-making. Current opinion in neurobiology 22:982-989.
  2. Cook, R. M, and B. J. Cockerell. 1978. Predator ingestion rate and its bearing on feeding time and the theory of optimal diets. Journal of Animal Ecology 47:529-54.
  3. Marginal Value Theorem. N.d. In Wikipedia., accessed July 21, 2014
  4. Parker, G. A. 1978. Searching for mates. In Behavioural Ecology: An Evolutionary Approach, First Edition. J. R. Krebs and N. B. Davies, eds. Pp. 214-244. Oxford:Blackwell Scientific Publications.
  5. Pyke, G.H. 2012. Optimal Foraging Theory: Introduction. In Encyclopedia of Animal Behavior. Michael D. Breed and Janice Moore, eds. Pp. 601-603. Oxford: Academic Press, Oxford.
  6. Watanabe, Y.Y., I. Motohiro, and A. Takahashi. 2014. Testing optimal foraging theory in a penguin-krill system. Proc. R. Soc. B 281:20132376.